javascript - webpack 4.1.1 -> configuration.module 有一个未知的属性 'loaders' 。

标签 javascript typescript webpack

我刚刚将 webpack 更新到 4.1.1,当我尝试运行它时出现以下错误:

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema. - configuration.module has an unknown property 'loaders'. These properties are valid: object { exprContextCritical?, exprContextRecursive?, exprContextRegExp?, exprContextRequest?, noParse?, rules?, defaultRules?, unknownContextCritical?, unknownContextRecursive?, unknownContextRegExp?, unknownContextRequest?, unsafeCache?, wrappedContextCritical?, wrappedContextRecursive?, wrappedContextRegExp?, strictExportPresence?, strictThisContextOnImports? } -> Options affecting the normal modules (NormalModuleFactory).

loaders 看起来像这样并与 webpack 3.11.0 一起工作:

module: {
    loaders: [
        { test: /\.tsx?$/, loader: ['ts-loader'] },
        { test: /\.css$/, loader: "style-loader!css-loader" },
        {
            test: /\.scss$/, use: [{
                loader: "style-loader" // creates style nodes from JS strings
            }, {
                loader: "css-loader" // translates CSS into CommonJS
            }, {
                loader: "sass-loader" // compiles Sass to CSS
            }]
        },
        { test: /\.(otf|ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/, loader: 'file-loader?name=./Scripts/dist/[name].[ext]' }
    ]
}

最佳答案

查看 webpack 4.1.1 的加载器示例:

https://webpack.js.org/loaders/raw-loader/

我所要做的就是将 loaders 重命名为 rules

module: {
    rules: [
        { test: /\.tsx?$/, loader: ['ts-loader'] },
        { test: /\.css$/, loader: "style-loader!css-loader" },
        {
            test: /\.scss$/, use: [{
                loader: "style-loader" // creates style nodes from JS strings
            }, {
                loader: "css-loader" // translates CSS into CommonJS
            }, {
                loader: "sass-loader" // compiles Sass to CSS
            }]
        },
        { test: /\.(otf|ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/, loader: 'file-loader?name=./Scripts/dist/[name].[ext]' }
    ]
}

关于javascript - webpack 4.1.1 -> configuration.module 有一个未知的属性 'loaders' 。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49203841/

相关文章:

javascript - 如何检查响应是否属于特定接口(interface)类型?

node.js - TS2585 : 'Promise' only refers to a type, 但在这里用作值

javascript - 在没有任何后端调用或数据库的情况下验证 AngularJS 中的用户

javascript - 无法创建一个使用 jQuery 使用键和 JSON 数组查找值的函数

javascript - 在 Marionette/Backbone.js 中渲染布局和 subview

javascript - MutationObserver — 仅在添加节点而不是删除节点时才做某事

angular - 使用具有多个通配符的 Globbing 模式在 TypeScript 中进行模块解析

javascript - 由于 MQTT.js 的存在,Webpack UglifyJS 在生产构建中出错

javascript - 使用 laravel mix 进行生产

angular - AOT 构建将组件模板留在最终包中