Webpack 2: How to exclude all node_modules except for

Leon Gaban picture Leon Gaban · Jul 21, 2017 · Viewed 8.4k times · Source

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?

Answer

roxxypoxxy picture roxxypoxxy · Jul 21, 2017

I think you can use regex, something like

exclude: [
  /node_modules\/(?!identicons).*/
]