Skip to content

Instantly share code, notes, and snippets.

@starikovs
Last active April 13, 2016 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save starikovs/1e45ad59f00b3003c8c7509f62527a52 to your computer and use it in GitHub Desktop.
Save starikovs/1e45ad59f00b3003c8c7509f62527a52 to your computer and use it in GitHub Desktop.
Webpack for Backbone.js
<script id="some-template" type="text/x-handlebars-template">
<input value="{{name}}">
</script>
<script>
// Inside view
const Hello = Backbone.View.extend({
el: '#hello-container',
template: Handlebars.compile($('#input-template').html()),
render: function () {
var html = this.template({name: this.model.get('name')}
this.$el.html(html);
}
});
const inputView = new InputView({
el: $('#input-container2'),
model: name
});
</script>
const NODE_ENV = process.env.NODE_ENV || 'development';
const webpack = require('webpack');
module.exports = {
context: __dirname + '/frontend',
entry: {
app: './app'
},
output: {
path: __dirname + '/public',
publicPath: '/',
filename: '[name].js'
},
devtool: NODE_ENV === 'development' ? 'inline-source-map' : null,
plugins: [
new webpack.NoErrorsPlugin(),
new webpack.DefinePlugin({
NODE_ENV: JSON.stringify(NODE_ENV)
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'common'
})
],
module: {
loaders: [{
test: /\.js$/,
loader: 'babel?presets[]=es2015'
}]
},
externals: {
'jquery': 'jQuery',
'underscore': '_',
'backbone': 'Backbone',
'handlebars': 'Handlebars'
}
/*watch: true,
watchOptions: {
aggregateTimeout: 100
}*/
};
if (NODE_ENV === 'production') {
module.exports.plugins.push(
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
drop_console: true,
unsafe: true
}
})
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment