我正在尝试通过babel-loader使用webpack 4和babel 6进行动态代码拆分,这是不可能的。看这段代码:
import Chunk1 from './chunks/Chunk1'
import('./chunks/Chunk2')
.then( module => {
Chunk2('Asynch')
})
;
Chunk1('Sync')
如果我不使用babel-loader,Webpack会将其分成2个块,但是当babel-loader加入混合时,束分离就结束了。这是我将babel-loader添加到webpack配置中的方法:
{
entry: {
main: path.resolve(appDirectory, 'chunkTest.js')
},
output: {
filename: '[name].bundle.js',
chunkFilename: '[name].chunk.js',
path: path.resolve(appDirectory, 'dist')
},
module: {
rules: [{
test: /\.m?js$/,
include: [
path.resolve(appDirectory, 'chunkTest.js'),
path.resolve(appDirectory, 'chunks')
],
use: {
loader: 'babel-loader',
options: {
// No options at all
}
}
]
},
}
我已经尝试了好几天没有运气,非常感谢您的帮助。我在做什么错了?