Webpack 2:如何排除除以下以外的所有node_modules [英] Webpack 2: How to exclude all node_modules except for

查看:653
本文介绍了Webpack 2:如何排除除以下以外的所有node_modules的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在/node_modules/identicons/上运行babel,但是我仍然想排除所有其他软件包.

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

原因为 identicons软件包 正在使用模板字符串和中断当我跑步

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

"webpack -p"

有问题的字符串(node_modules/identicons/index.js):

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"]
    },

该模式将如何编写?

推荐答案

我认为您可以使用正则表达式,例如

I think you can use regex, something like

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

这篇关于Webpack 2:如何排除除以下以外的所有node_modules的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆