如何在webpack中将源文件与所有供应商分开?

时间:2015-11-19 06:27:42

标签: javascript configuration webpack

我希望有两个文件app.bundle.jsvendors.js,其中app.bundle.js只包含 我编写的代码。有可能吗?

以下是我的webpack.config.js文件

const dependencies = _.keys(packageConfig["dependencies"])

export default {
    entry: {
        vendors: dependencies,
        app: [
            'webpack-hot-middleware/client',
            './src/js/entry.js'
        ]
    },
    output: {
        path: path.join(__dirname, 'dist'),
        filename: '[name].bundle.js',
        publicPath: '/'
    },

    ...

    plugins: [
        new webpack.optimize.CommonsChunkPlugin('vendors', 'vendors.js'),
        ...

但它不起作用。编译时我总是遇到错误,因为找不到某些模块。我试图手动列出所有依赖项,但在这种情况下,我在app.bundle.js中有第三方代码。那么它甚至可能吗?

更新

我已经看了一下编译好的app.bundle.js并看到了热替换模块和webpack本身的代码。所以真正的问题是 - 这是一个必须放在每个webpack模块中的默认代码吗?

更新

我在条目文件中的第一行是import 'babel-core/polyfill',所以我希望模块babel-core位于vendors.js。并有这个错误

ERROR in ./~/babel-core/~/regenerator/lib/visit.js
Module not found: Error: Cannot resolve module 'fs' in /Users/vitalii/Documents/coding/timerrrs/node_modules/babel-core/node_modules/regenerator/lib
 @ ./~/babel-core/~/regenerator/lib/visit.js 12:9-22

ERROR in ./~/babel-core/~/regexpu/data/iu-mappings.json
Module parse failed: /Users/vitalii/Documents/coding/timerrrs/node_modules/babel-core/node_modules/regexpu/data/iu-mappings.json Line 2: Unexpected token :
You may need an appropriate loader to handle this file type.
| {
|   "75": 8490,
|   "83": 383,
|   "107": 8490,
 @ ./~/babel-core/~/regexpu/rewrite-pattern.js 4:17-51

ERROR in ./~/babel-core/~/globals/globals.json
Module parse failed: /Users/vitalii/Documents/coding/timerrrs/node_modules/babel-core/node_modules/globals/globals.json Line 2: Unexpected token :
You may need an appropriate loader to handle this file type.
| {
|   "builtin": {
|       "Array": false,
|       "ArrayBuffer": false,
 @ ./~/babel-core/~/globals/index.js 1:17-42

ERROR in ./~/babel-core/~/regenerator/~/recast/main.js
Module not found: Error: Cannot resolve module 'fs' in /Users/vitalii/Documents/coding/timerrrs/node_modules/babel-core/node_modules/regenerator/node_modules/recast
 @ ./~/babel-core/~/regenerator/~/recast/main.js 18:4-17

0 个答案:

没有答案