有没有办法在全球范围内从 webpack 中排除 node_modules?

Is there a way to exclude node_modules from webpack on a global levle?

我有一个简单的演示配置,可以从 js 和 jsx 文件中排除节点模块,但是找不到全局排除 node_modules 的解决方案,所以我不需要总是在每个文件中指定这个排除装载机

const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const ExtractTextPlugin = require("extract-text-webpack-plugin");

module.exports = {
  entry: {
    app: path.resolve(__dirname, "../src/index.js")
  },
  output: {
    path: path.resolve(__dirname, "../dist"),
    filename: "[name].[chunkhash].js",
    publicPath: "/",
    chunkFilename: "[name].[chunkhash].js"
  },
  module: {
    rules: [
      { test: /\.js$/, loaders: ["babel-loader"], exclude: /node_modules/ },
      { test: /\.jsx$/, loaders: ["babel-loader"], exclude: /node_modules/ },
      {
        test: /\.css$/,
        use: ExtractTextPlugin.extract({
          fallback: "style-loader",
          use: "css-loader"
        })
      }
    ]
  },
  plugins: [
    new CleanWebpackPlugin([path.resolve(__dirname, "../dist")]),
    new HtmlWebpackPlugin({ template: path.resolve(__dirname, "../public/index.html") }),
    new ExtractTextPlugin("styles.css")
  ]
};

有办法实现吗?我在 webpack 3

您可以使用

{ test: /\.jsx?$/, loaders: ["babel-loader"], exclude: /node_modules/ },