Last active
April 13, 2016 19:34
-
-
Save starikovs/1e45ad59f00b3003c8c7509f62527a52 to your computer and use it in GitHub Desktop.
Webpack for Backbone.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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