繁体   English   中英

webpack 2延迟加载

[英]webpack 2 lazy loading

我有具有通用依赖项的动态导入模块,并且我需要common.js和g.js(在此示例中),但是它不起作用,我有空的common。 怎么了? 我想与g.js通用

index.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,
           }))
    ]
};

暂无
暂无

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

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