Webpack忽略了生产构建的分块

时间:2016-10-06 17:29:24

标签: javascript webpack

我有一个Webpack配置,它在我的项目中拆分我的代码。我想要做的是忽略分块并生成单个文件,如果它是生产版本。

这是我的webpack配置文件: https://gist.github.com/alyn000r/5663c1036ab8e60695ba4db4e866df5f

这是我的index.js,因为正在发生分块:

if (typeof require.ensure !== `function`) require.ensure = (d, c) => c(require);  // mocha test runner polyfill

/**
 * require.ensure allows asynchronous chunk loading of the component, which means an extra HTTP hop to download the component,
 * in exchange of smaller initial download footprint.
 * - Use require.ensure for components that are least frequently used
 * - Use require.ensure for components that import libraries that are large in size
 */
export function lookup(componentName, callback) {
    switch (componentName) {
        // ============================== Components ===============================
        case 'dD':
            callback(require('./components/dD'));
            break;
        case 'eBL':
            callback(require('./components/eBL'));
            break;
        case 'essay':
            callback(require('./components/essay'));
            break;
        case 'hSM':
            require.ensure([], require => callback(require('./components/hSM')));
            break; 

这就是它现在的产生:

enter image description here

如果(isProduction)为真,请帮我生成一个文件

我尝试删除CommonChunks插件和MinChunkSizePlugin,如果isProduction但仍然发生了块。我也试图删除

jsonpFunction: `jsonpFunction${jsonpPackageName}`,
    chunkFilename: `${packageName}/${packageName}-[id].js`,

但它仍会生成0.0.js,1.1.js,2.2.js ....

请告诉我我错过了什么。谢谢

1 个答案:

答案 0 :(得分:0)

您可以使用LimitChunkCountPlugin将最大块数限制为1来禁用代码拆分:

plugins: [
    new webpack.optimize.LimitChunkCountPlugin({
        maxChunks: 1
    });
]