我的错误输出:
配置对象无效。Webpack 已使用与 API 模式不匹配的配置对象进行初始化。- configuration.module 有一个未知的属性 ‘loaders’。这些属性是有效的:object { exprContextCritical?, exprContextRecursive?, exprContextRegExp?, exprContextRequest?, noParse?, rules?, defaultRules?, unknownContextCritical?, unknownContextRecursive?, unknownContextRegExp?, unknownContextRequest?, unsafeCache?, WrappedContextCritical?, WrappedContextRecursive?, WrappedContextRegExp ?, strictExportPresence?, strictThisContextOnImports? } -> 影响正常模块的选项 ( NormalModuleFactory)。
NormalModuleFactory
我的 webpack.config.js:
var webpack = require('webpack'); var path = require('path'); var BUILD_DIR = path.resolve(__dirname, 'src/client/public'); var APP_DIR = path.resolve(__dirname, 'src/client/app'); var config = { entry: APP_DIR + '/index.jsx', module : { loaders : [ { test : /\.jsx?/, include : APP_DIR, loader : 'babel-loader' } ] }, output: { path: BUILD_DIR, filename: 'bundle.js' } }; module.exports = config;
我的 webpack 版本:
webpack@4.1.1
您应该在 webpack 4 中更改loaders为:rules
loaders
rules
改变:
至:
来源:装载机
例子:
module.exports = { module: { rules: [ { test: /\.css$/, use: 'css-loader' }, { test: /\.ts$/, use: 'ts-loader' } ] } };