【问题标题】:Is there a way to exclude node_modules from webpack on a global levle?有没有办法在全球范围内从 webpack 中排除 node_modules?
【发布时间】:2018-03-25 12:01:08
【问题描述】:

我有简单的演示配置,从 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 上

【问题讨论】:

    标签: javascript webpack bundle node-modules


    【解决方案1】:

    你可以使用

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多