从webpack打包中排除特定文件

3
在我的 React 应用中,我正在使用 Webpack。这是我的 webpack.config 配置文件:
"use strict";

var path = require("path");
var WebpackNotifierPlugin = require("webpack-notifier");
var BrowserSyncPlugin = require("browser-sync-webpack-plugin");

module.exports = {
    entry: "./Scripts/reactApp/index.jsx",
    output: {
        path: path.resolve(__dirname, "./Scripts/reactApp/build"),
        filename: "react_bundle.js"
    },
    module: {
        rules: [
            {
                test: /\.jsx$/,
                exclude: [/node_modules/, path.resolve(__dirname, "./Scripts/reactApp/translations/he.translations.json")],
                use: {
                    loader: "babel-loader"
                }
            },
            {
                test: /\.js$/,
                exclude: [/node_modules/, path.resolve(__dirname, "./Scripts/reactApp/translations/he.translations.json")],
                use: {
                    loader: "babel-loader"
                }
            }
        ]
    },
    devtool: "inline-source-map",
    plugins: [new WebpackNotifierPlugin(), new BrowserSyncPlugin()]
};

我正在尝试从捆绑包中排除 he.translations.json,但无论如何 webpack 都会将它包含进去。

enter image description here

你能解释一下我做错了什么吗?提前道歉,我对webpack还很新。
1个回答

1
你可以直接从webpack文档中进行操作。
...
exclude: [/node_modules/, path.resolve(__dirname, 'Scripts/reactApp/translations/he.translations.json')],
...

路径中没有点,当然,假设你已经将webpack配置文件放在了正确的位置。

这应该是被接受的答案!适用于 WebPack 5。 { test: /\.(js|jsx)$/, exclude: [/node_modules/, path.resolve(__dirname, 'src/index.js')], use: { loader: 'babel-loader', options: { presets: ['@babel/preset-env', '@babel/preset-react'] } } - C-Dev

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接