2

我的 webpack.config.js 有什么问题,因为它无法排除 node_modules。我在以前版本的 webpack 中发现了关于这个问题的类似帖子,但是由于语法不同,修复不起作用......

    module.exports = {
        context: __dirname,
        entry: './src/index.js',
        output: {
            path: __dirname + '/public/assets/',
            publicPath: '/assets/js/',
            filename: 'bundle.js'
        },

        module: {
            rules: [
                {
                    test: /\.css$/,
                    include: /src/,
                    exclude: /node_modules/,
                    use: [
                        {loader: 'style-loader'},
                        {loader: 'css-loader'}
                    ]
                },
                {
                    test: /\.ejs$/,
                    include: /src/,
                    exclude: /node_modules/,
                    use: [
                        {loader: 'ejs-simple-loader'}
                    ]
                },
                {
                    test: /\.js$/,
                    include: /src/,
                    exclude: /node_modules/,
                    use: [
                        {loader: 'jshint-loader'}
                    ]
                },
                {
                    test: /\.jsx$/,
                    include: /src/,
                    exclude: /node_modules/,
                    use: [
                        {loader: 'babel-loader'}
                    ]
                }
            ]
        }
    }
4

1 回答 1

2

您正在使用需要该pre值的规则。

您的代码应为:

module.exports = {
    entry: "./foo.js",
    output: {
        filename: "./bar.js"
    },

    module: {
        rules: [
            {
                test: /\.js$/,
                enforce: 'pre', // updated value
                exclude: /node_modules/,
                use: [
                    { loader: 'jshint-loader' }
                ]
            }
        ]
    }
};

来源:https ://webpack.js.org/configuration/module/#rule-enforce

于 2018-01-12T22:23:23.877 回答