我正在尝试使用Module Dynamic Import创建具有npm软件包的捆绑包,这是一个很好的教程:https://webpack.js.org/guides/code-splitting/
但是我要动态加载的npm软件包具有其自身的块依赖关系:
npm package chunk dependencies
我可以看到Webpack正确地创建了供应商块:
但是要导入的块的npm包没有重新导入,因此失败:
我在Google上搜索了很多,但是找不到很多信息,而且我不知道这是错误,配置错误还是不可能。
配置:
// my-project/index.js
const initializeLiveAR = await import(/* webpackChunkName: */ 'revieve-livear-module'); "livear_[index]"
// webpack.config.js
module.exports = {
entry: {
'revieve-sdk': path.resolve(__dirname, config.main_entry),
demoAR: path.resolve(__dirname, config.demoAR),
demoPR: path.resolve(__dirname, config.demoPR),
},
devtool: 'source-map',
mode: process.env.NODE_ENV,
output: {
path: path.resolve(__dirname, 'build'),
publicPath: '/',
filename: '[name].min.js',
chunkFilename: '[name].chunk.js',
libraryTarget: 'umd',
},
plugins: [
process.env.ANALYZEBUNDLE ? new BundleAnalyzerPlugin() : function() {},
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
}),
new CopyWebpackPlugin([
{ from: 'index.html', to: '.' },
{ from: 'test', to: './test' },
{ from: 'changelog.md', to: '.' },
]),
],
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.css$/,
use: [{ loader: 'style-loader' }, { loader: 'css-loader' }],
},
],
},
};