Webpack 3不排除node_modules

ryevplcw  于 2023-05-07  发布在  Webpack
关注(0)|答案(1)|浏览(150)

这里我的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'}
                    ]
                }
            ]
        }
    }
jchrr9hc

jchrr9hc1#

您正在使用需要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/#ruleenforce

相关问题