Bundle-loader 的webpack配置怎么写?

按照官方的介绍是这样加载的

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']
            }
           //...
        ]
    },
阅读 5.8k
2 个回答

me too, but the error was cb is not function.

新手上路,请多包涵

检查一下正则是不是匹配到文件了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题