我在stackoverflow上到处都看到了这个错误,但是对我没有任何作用。我试图在开发人员和生产模式下运行webpack,但是在运行webpack ---config webpack.dev.js --watch
Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
- configuration has an unknown property '1'. These properties are valid:
object { amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry?, externals?, loader?, mode?, module?, name?, node?, optimization?, output?, parallelism?, performance?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, serve?, stats?, target?, watch?, watchOptions? }
For typos: please correct them.
For loader options: webpack >= v2.0.0 no longer allows custom properties in configuration.
Loaders should be updated to allow passing options via loader options in module.rules.
Until loaders are updated one can use the LoaderOptionsPlugin to pass these options to the loader:
plugins: [
new webpack.LoaderOptionsPlugin({
// test: /\.xxx$/, // may apply this only for some modules
options: {
1: …
}
})
]
这里是所有配置的方式:
webpack.base.js
var path = require('path');
var webpack = require('webpack');
var BundleTracker = require('webpack-bundle-tracker');
module.exports = [{
entry: './assets/js/script',
plugins: [
new BundleTracker({filename: './webpack-stats.json'})
],
module: {
rules: [
{ test: /\.jsx?$/, exclude: /node_modules/, loader: 'babel-loader'},
],
},
resolve: {
modules: ['node_modules', 'bower_components', path.resolve(__dirname, 'assets/js/'),],
extensions: ['.js', '.jsx']
}
},{
context: __dirname,
entry: './assets/scss/style.scss',
module: {
rules: [
{
test: /\.css$/,
loaders: [
'style-loader',
'css-loader',
],
},
{
test: /\.scss$/,
loaders: [
'style-loader',
'css-loader',
'sass-loader',
],
},
{
test: /\.(svg)(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url-loader?limit=100000',
},
{
test: /\.(jpg|png)?$/,
loaders: [
'file-loader?name=i-[hash].[ext]',
],
},
]
}
}]
webpack.dev.js
var path = require('path');
var webpack = require('webpack');
var base = require("./webpack.base");
var merge = require("webpack-merge");
var BundleTracker = require('webpack-bundle-tracker');
module.exports = merge(base, [{
mode: "development",
output: {
path: path.resolve('./assets/js/min/'),
filename: "[name].js"
},
},{
mode: "development",
output: {
path: path.resolve('./assets/scss/min/'),
filename: "[name].js"
},
}]);
webpack.prod.js:
var path = require('path');
var webpack = require('webpack');
var base = require("./webpack.base");
var merge = require("webpack-merge");
var BundleTracker = require('webpack-bundle-tracker');
module.exports = merge(base, [{
mode: "production",
output: {
path: path.resolve('./assets/js/min/'),
filename: "[name].[contentHash].js"
},
},{
mode: "production",
output: {
path: path.resolve('./assets/scss/min/'),
filename: "[name].[contentHash].js"
},
}]);
我知道配置设置不寻常,但是当所有内容都在一个文件中时它可以工作。我该怎么办?