ThomasReggi
ThomasReggi

Reputation: 59495

How to include specific node_modules to load into webpack?

I'm using react-native-web and I've come across a couple of projects that do not compile their babel code (react-native-popover and react-native-vector-icons). So I need to compile these node_modules. I know the babel-preset-react-native preset exists. Is there any way I can use the babel loader I currently have (see below) and also include another loader for the above mentioned packages? Ideally any node_module that is prefaced with react-native would be loaded using babel-preset-react-native.

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

Upvotes: 1

Views: 4482

Answers (1)

Joe Ruello
Joe Ruello

Reputation: 1206

Exclude takes a regular expression. You can use something like this to get your desired effect.

exclude: /node_modules\/(?!react-native)/

Upvotes: 4

Related Questions