user237329
user237329

Reputation: 819

Using webpack with 'react-hot', 'babel-loader'

I have a webpack.config with loaders like this:

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

I exclude node_modules because other ways react-hot would get in trouble saying things like this

My problem is that: by excluding node_module, a private npm package that needs babel-loader, would not be loaded into the bundle.

How can I manage excluding for each loader?

Upvotes: 1

Views: 483

Answers (1)

franky
franky

Reputation: 1333

You can use the include property for the loader instead of exclude. For example:

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

Note that both webpack and react-hot-loader recommend using include over exclude whenever possible.

Upvotes: 4

Related Questions