10

I need to have babel run on /node_modules/identicons/ However I still want to exclude all other packages.

Reason is the identicons package is using template strings and breaks when I run

"webpack -p"

String in question (node_modules/identicons/index.js):

str += `<rect x="${x}" y="${y}" width="${xside}" height="${xside}" style="fill:${color}" />` 

Webpack.config.babel

module: { rules: [ { test: /\.jsx?$/, exclude: /node_modules/, //include: /node_modules/identicons/, use: ["babel-loader"] }, 

How would that pattern be written?

4 Answers 4

16

I think you can use regex, something like

exclude: [ /node_modules\/(?!identicons).*/ ] 
Sign up to request clarification or add additional context in comments.

Comments

5

Another way:

exclude: [ { test: [ path.resolve(__dirname, './node_modules'), ], exclude: [ path.resolve(__dirname, './node_modules/MODULE_TO_INCLUDE'), path.resolve(__dirname, './node_modules/ANOTHER_MODULE_TO_INCLUDE'), ] } ] 

It worked for me.

Comments

4

You could exclude everything from node_modules that is not identicons:

exclude: /node_modules\/(?!identicons$)/ 

Comments

3

Exclude whole node_modules folder, except required module:

{ test: /\.js$/, exclude: /node_modules\/(?!identicons\/).*/, } 

https://github.com/webpack/webpack/issues/2031#issuecomment-219040479

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.