Webpack 3和CommonsChunkPlugin - 从要求供应商中排除特定入口点

时间:2018-04-17 03:30:43

标签: javascript webpack

我正在处理大量商业软件,这些软件正在慢慢迁移到所有页面上使用Webpack。我想开始将一些webpack-bundled helper typescript代码整合到尚未开始使用webpack的页面中 - 它们包含了老式的脚本。

以下是配置的相关部分:

entry: {
    vendor: [
        // All vendor scripts go here
    ],

    // All entry points for 'webpack' pages...

    // A special entry point that I want to inject into non-webpack pages
    es5Compatibility: [
        'Utility/ES5Compatibility.ts'
    ]
},

// ...

output: {
    path: path.join(__dirname, 'Scripts/bundle'),
    filename: '[name].[chunkhash].bundle.js',
    chunkFilename: '[id].chunk.js'
},
plugins: [
    // ...

    new webpack.optimize.CommonsChunkPlugin({
        name: 'vendor',
        minChunks: Infinity
    })

    // This should NOT get injected into non-webpack pages, as all of the
    // vendor dependencies already exist there
    new HtmlWebpackPlugin({
        chunks: ['vendor'],
        template: 'bundleTemplate.ejs',
        inject: false,
        filename: '_VendorBundle.html'
    }),

    // This should get injected into non-webpack pages WITHOUT requiring
    // the above bundle to be included
    new HtmlWebpackPlugin({
        chunks: ['es5Compatibility'],
        template: 'bundleTemplate.ejs',
        inject: false,
        filename: '_ES5CompatibilityBundle.html'
    }),

    // ...
    new webpack.HashedModuleIdsPlugin(),
]

问题是,当_ES5CompatibilityBundle.html包含在没有VendorBundle.html的页面中时,我得到以下Javascript错误,因为Webpack期望包含供应商包:

Uncaught ReferenceError: webpackJsonp is not defined

如何告诉Webpack将ES5兼容包捆绑为一个独立的'捆绑,同时保留webpack页面的公共块功能?

0 个答案:

没有答案