【发布时间】:2018-05-11 23:25:01
【问题描述】:
我得到一个
Webpack 已使用与 API 架构不匹配的配置对象进行初始化。 - 配置应该是一个对象。
当我尝试使用以下行通过 webpack node api 要求 webpack 配置时:
var webpack = require('webpack');
var webpackConfig = require('./webpack.config.js');
webpack(webpackConfig);
我可以使用 npm cli 从同一个文件夹中构建完全相同的 webpack.config.js
webpack
这可能是什么问题?
webpack 配置如下所示:
const webpack = require('webpack');
const path = require("path");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
module.exports = function(env) {
return {
entry: path.resolve(__dirname, "src/index.js"),
output: {
filename: "./bundle.js",
path: env!==undefined&&('output_path' in env)? env.output_path : path.resolve(__dirname, "bin")
},
externals: [
"angular",
"uuid",
{
"lodash": {
commonjs: "lodash",
amd: "lodash",
root: "_" // indicates global variable
}
},
{
"jquery": {
root: "$",
amd: "jquery",
commonjs: 'jquery'
}
},
{
"jquery-ui": {
amd: "jquery-ui",
commonjs: 'jquery-ui'
}
},
{
"Slick": {
root: "Slick",
amd: "Slick",
commonjs: 'Slick'
}
}
],
devtool: 'source-map',
resolve: {
extensions: ['.webpack.js', '.web.js', '.js'],
},
module: {
rules: [
{
test: /\.html$/,
use: "html-loader"
},
{
test: /.*\.less$/,
use: ExtractTextPlugin.extract({
use:[ 'css-loader', 'less-loader' ],
})
}
]
},
plugins: [
new ExtractTextPlugin({ filename: 'module.css', disable: false, allChunks: true })
]
};
};
【问题讨论】: