Webpack CommonJS backbone and underline

I would like to use Backbone with a CommonJS style webpack, but I need to understand how:

  • Tell the website that Backbone is underscore dependent
  • Prevent automatic disconnection from AMD

Seems like there imports-loader

might be an answer. Do I need something like this in my config?

module: {
    loaders: [
        {
            test: require.resolve('_'),
            loader: 'imports?_=underscore,define=>false'
        },
        {
            test: require.resolve('backbone'),
            loader: 'imports?define=>false'
        }
    ]
},

      

Also, will it make it so that I don't have to do var _ = require('underscore');

before I'm var Backbone = require('backbone');

all over the place?

My question can be considered a duplicate of this , but I hope to get a little more clarification than the accepted answer provides.

+3


source to share


1 answer


If you installed the pipeline via npm, this should be required via CommonJS. When they are installed, NPM modules also automatically fetch and install their dependencies in their own folder node_modules

, which means you don't have to worry about highlighting the underline for the trunk.



+5


source







All Articles