[英]Webpack config has an unknown property 'preLoaders'
I'm learning webpack from scratch. 我正在从头开始学习webpack。 I've learned how to link javascript files with require. 我已经学会了如何将javascript文件与require链接起来。 I'm bundling and minifying my js files and i'm listening for changes with watch. 我正在捆绑和缩小我的js文件,我正在监听手表的变化。 I'm setting up loaders to convert my sass files to css. 我正在设置加载器将我的sass文件转换为css。 But when I try to setup a linting process with jshint-loader, i'm running into issues. 但是当我尝试使用jshint-loader设置linting过程时,我遇到了问题。
module: {
preLoaders: [
{
test: /\.js$/, // include .js files
exclude: /node_modules/, // exclude any and all files in the node_modules folder
loader: "jshint-loader"
}
],
loaders: [
{
test: /\.scss$/,
loader: 'style-loader!css-loader!sass-loader'
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules$/,
query: {
presets: ['es2015']
}
}
],
} }
Here is the error 这是错误
Invalid configuration object. 配置对象无效。 Webpack has been initialised using a configuration object that does not match the API schema. Webpack已使用与API架构不匹配的配置对象进行初始化。 - configuration.module has an unknown property 'preLoaders'. - configuration.module有一个未知属性'preLoaders'。 These properties are valid: object { exprContextCritical?, exprContextRecursive?, exprContextRegExp?, exprContextRequest?, loaders?, noParse?, rules?, unknownContextCritical?, unknownContextRecursive?, unknownContextRegExp?, unknownContextRequest?, unsafeCache?, wrappedContextCritical?, wrappedContextRecursive?, wrappedContextRegExp? 这些属性是有效的:object {exprContextCritical?,exprContextRecursive?,exprContextRegExp?,exprContextRequest?,loaders?,noParse ?, rules ?, unknownContextCritical?,unknownContextRecursive?,unknownContextRegExp?,unknownContextRequest?,unsafeCache?,wrappedContextCritical?,wrappedContextRecursive?,wrappedContextRegExp ? } Options affecting the normal modules (
NormalModuleFactory
). 影响正常模块的选项(NormalModuleFactory
)。
From v2.1-beta.23 the loaders section is renamed to rules and pre/postLoaders is now defined under each rule with the enforce property. 从v2.1-beta.23开始 ,加载器部分被重命名为规则,现在在每个规则下使用enforce属性定义pre / postLoaders。
So just rename preLoaders
to rules
and you should be good to go ;-) 所以只需将preLoaders
重命名为rules
,你应该好好去;-)
First uninstall webpack 首先卸载webpack
npm uninstall webpack --save-dev
followed by 其次是
npm install webpack@2.1.0-beta.22 --save-dev
if you are using webpack 2 then you may use the enforce: 'pre' tag inside the loaders array and this will work as a preload please refer code below for details 如果您正在使用webpack 2,那么您可以在加载器数组中使用enforce:'pre'标签,这将作为预加载,请参阅下面的代码了解详细信息
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'jshint-loader',
//this is similar to defining a preloader
enforce: 'pre'
},
{
test: /\.es6$/,
exclude: /node_modules/,
loader: "babel-loader"
}
]
},
use this one instead ./webpack.config.js 请使用此代码./webpack.config.js
var path = require('path');
module.exports = {
entry: './main.ts',
resolve: {
extensions: ['.webpack.js', '.web.js', '.ts', '.js']
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
}
]
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
}
}
the documentation can be found here the problem is related to the version of ts-loader you installed 在这里可以找到文档,问题与您安装的ts-loader版本有关
对我来说,只需将“装载机”改为“规则”即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.