按照官方的介绍是这样加载的
require('bundle?lazy&name=essay!../containers/essay'))
但是看了篇外国的文章大概说可以在webpack
配置,然后设置指定的文件路径都用bundle-loader
加载(?),不用每个require()
都加bundle?lazy
引用原话:
Once we’ve updated the file structure, we can direct webpack to run route components through bundle-loader. Since we don’t want to split every single file in routes/ (specifically the files in components/ directories), we will need to write a regex to match the right files. In this particular app, we know route components are any files matching routes/.js or routes/SOMETHING/.js. Any files matching routes/SOMETHING/components/*.js should NOT be included:
// NOTE: this assumes you're on a Unix system. You will
// need to update this regex and possibly some other config
// to get this working on Windows (but it can still work!)
var routeComponentRegex = /routes\/([^\/]+\/?[^\/]+).js$/
module.exports = {
// ...rest of config...
modules: {
loaders: [
// make sure to exclude route components here
{
test: /\.js$/,
include: path.resolve(__dirname, 'src'),
exclude: routeComponentRegex,
loader: 'babel'
},
// run route components through bundle-loader
{
test: routeComponentRegex,
include: path.resolve(__dirname, 'src'),
loaders: ['bundle?lazy', 'babel']
}
]
}
// ...rest of config...
}
但是我按照他的配置出现以下错误:
client.js:5063Uncaught TypeError: Cannot call a class as a function
我的webpack配置:
module: {
loaders: [
//...
{
test: /\/app\/([^\/]+\/?[^\/]+).js$/,
loaders: ['bundle?lazy', 'babel']
}
//...
]
},
me too, but the error was cb is not function.