webpack 2 延迟加载



我有具有共同依赖关系的动态导入模块,我需要 common.js 与 g.js(在本例中),但它不起作用,我有空的 common。怎么了?我想与g共同点.js

索引.js

System.import("./d")
    .then( (module) => {
    });
System.import("./t")
    .then( (module) => {
    });

t.js

import "./g";
module.exports = {
    x: 5
}

d.js

import "./g";
export function message() {
    alert("msg")
}

webpack.config.js

module.exports = {
    entry: {index: "./index.js"},
    context: __dirname,
    output: {
        filename: "dist/[name].js"
    },
    resolve: {
        modules: [
            "bower_components",
            path.resolve('./'),
        ],
    },
    plugins: [
       new webpack.optimize.CommonsChunkPlugin({
            name: `common`,
            async: true
        })
    ]
};
module.exports = {
    entry: {index: "./index.js"},
    context: __dirname,
    output: {
        filename: "dist/[name].js"
    },
    resolve: {
        modules: [
            "bower_components",
            path.resolve('./'),
        ],
    },
    plugins: [
        new webpack.optimize.CommonsChunkPlugin({
                children: true,
                async: true,
           }))
    ]
};

最新更新