从Webpack包中排除特定文件

时间:2019-07-01 12:30:03

标签: javascript reactjs webpack bundle

在我的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 个答案:

答案 0 :(得分:0)

您可以(从webpack docs开始)

...
exclude: [/node_modules/, path.resolve(__dirname, 'Scripts/reactApp/translations/he.translations.json')],
...

路径中没有点,当然,假设您在适当的位置有wepback配置文件。