Webpack 2: How to exclude all node_modules except for

时光怂恿深爱的人放手 提交于 2019-12-23 10:12:12

问题


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?


回答1:


I think you can use regex, something like

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



回答2:


You could exclude everything from node_modules that is not identicons:

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



回答3:


Exclude whole node_modules folder, except required module:

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

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



来源:https://stackoverflow.com/questions/45246365/webpack-2-how-to-exclude-all-node-modules-except-for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!