I'd like to use Backbone with webpack in the CommonJS style, but I need to understand how to:
It seems like imports-loader might be the answer. Do I want something like this in my configuration?
module: {
loaders: [
{
test: require.resolve('_'),
loader: 'imports?_=underscore,define=>false'
},
{
test: require.resolve('backbone'),
loader: 'imports?define=>false'
}
]
},
Also, will this make it so I don't have to do var _ = require('underscore'); before I do var Backbone = require('backbone'); everywhere?
My question might be deemed a duplicate of this, but I hope to get a little more clarification than provided in the accepted answer there.
If you've installed backbone via npm, it should be required via CommonJS. When installed, NPM modules also automatically retrieve and install their dependencies in their own node_modules folder, which means you don't have to worry about providing underscore to backbone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With