webpack 2 延迟加载
webpack 2 lazy loading
我有具有共同依赖性的动态导入模块,我需要 common.js 和 g.js(在这个例子中),但它不起作用,我有空的共同点。
怎么了?
我想与 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,
}))
]
};
我有具有共同依赖性的动态导入模块,我需要 common.js 和 g.js(在这个例子中),但它不起作用,我有空的共同点。 怎么了? 我想与 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,
}))
]
};