简体   繁体   English

webpack CommonJS骨干和下划线

[英]webpack CommonJS backbone and underscore

I'd like to use Backbone with webpack in the CommonJS style, but I need to understand how to: 我想在CommonJS风格中使用Backbone和webpack,但我需要了解如何:

  • Tell webpack that Backbone depends on underscore 告诉webpack,Backbone依赖于下划线
  • Prevent them from automatically defaulting to AMD 防止他们自动默认为AMD

It seems like imports-loader might be the answer. 似乎imports-loader可能就是答案。 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'); 另外,这样做会使我不必做var _ = require('underscore'); before I do var Backbone = require('backbone'); 在我做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. 如果你通过npm安装了主干,那么应该通过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. 安装后,NPM模块还会自动在其自己的node_modules文件夹中检索和安装它们的依赖node_modules ,这意味着您不必担心为主干提供下划线。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM