Webpack 3 不排除 node_modules

标签 webpack webpack-3

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

最佳答案

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

关于Webpack 3 不排除 node_modules,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48080976/

相关文章:

css - 媒体查询不适用于 CSS/样式加载器和 Webpack3

javascript - "Module {path}\src\app\sales\models\index.ts has no static exports"是什么意思,我该如何解决?

javascript - 使用 webpack 定义全局变量

javascript - 如何在不使用 Module.default 符号的情况下将我的模块导出到浏览器?

javascript - Webpack > 无法使用原始源代码进行调试(JSX 等)

angularjs - 使用 Webpack 和 AngularJS 在生产中图像 GET 抛出 404 错误

javascript - 动态导入会分割代码但不会延迟加载

reactjs - React Nextjs : Module parse failed:You may need an appropriate loader to handle this file type, 当前没有配置加载器来处理这个文件

reactjs - 如何在 NextJS 配置文件中组合多个加载器(CSS、LESS、ttf 等)?

javascript - 如何获取 Angular 4 项目构建中包含的 .json 文件?