【问题标题】:Using webpack with 'react-hot', 'babel-loader'使用带有 'react-hot'、'babel-loader' 的 webpack
【发布时间】:2015-12-03 18:07:38
【问题描述】:

我有一个带有如下加载器的 webpack.config:

   loaders: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loaders: [ 'react-hot', 'babel-loader' ]
      },
      {
        exclude: /node_modules/,
        loader: 'eslint-loader',
        test: /\.js$/
      }
    ],

我将 node_modules 排除在外,因为其他方式 react-hot 会遇到麻烦,比如 this

我的问题是:通过排除 node_module,一个需要 babel-loader 的私有 npm 包不会被加载到包中。

如何管理每个加载程序的排除?

【问题讨论】:

  • 把你的私有包放在不同的地方(例如项目文件夹下的lib)可以解决这个问题。

标签: reactjs webpack


【解决方案1】:

您可以为加载程序使用include 属性,而不是exclude。例如:

loaders: [
  {
    test: /\.js$/,
    include: [
      path.resolve(__dirname, "app/src"),
      // some module in node_modules folder
    ],
    loaders: [ 'react-hot', 'babel-loader' ]
  },
  ...
],

请注意,webpackreact-hot-loader 都建议尽可能使用 include 而不是 exclude

【讨论】:

    猜你喜欢
    • 2016-07-28
    • 2016-05-30
    • 2017-01-06
    • 2020-06-05
    • 2016-02-28
    • 2020-01-01
    • 2016-06-14
    • 2018-02-11
    • 1970-01-01
    相关资源
    最近更新 更多