如图全局安装了webpack但是出现了undefined的情况,而且webpack命令运行,也是输出undefined,但是在webpack.config.js中写的console会照常打印,求帮助
初步估计问题出在webpack.config的入口entry中
最后输出为动态生成
var path = require('path');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
var merge = require('webpack-merge');
var webpack=require('webpack');
function resolve (dir) {
return path.join(__dirname, dir)
}
var template_dir=path.join(__dirname,'..', 'templates')
var app=['danyuanceshi'];
var templates=['paper/template_danyuanceshi'];
var entry={};
if (Array.isArray(app)) {
app.forEach(function(item) {
entry[item] = "./app/" +item + ".js";
});
}
else {
entry[app] = __dirname + "/app/" + app + ".js";
}
/*console.log(entry);*/
var plugins=[
new webpack.optimize.DedupePlugin(),
function()
{
this.plugin("done", function(stats)
{
if (stats.compilation.errors && stats.compilation.errors.length)
{
// console.log(stats.compilation.errors);
//console.log(stats.compilation.errors[stats.compilation.errors.length-1].issuer);
console.log(stats.compilation.errors[stats.compilation.errors.length-1].message);
if (stats.compilation.errors[stats.compilation.errors.length-1].details) {
console.log(stats.compilation.errors[stats.compilation.errors.length-1].details);
}
process.exit(1);
}
});
},
// new webpack.NoEmitOnErrorsPlugin(),
new FriendlyErrorsPlugin()
]
if(Array.isArray(templates)){
templates.forEach(function (item) {
plugins.push(new HtmlWebpackPlugin({
filename: template_dir+item+'.html',
template: item+'.html',
inject: true
}))
})
}else{
plugins.push(new HtmlWebpackPlugin({
filename: templates+'.html',
template: template_dir+templates+'.html',
inject: true
}))
}
var extraWebpackConfig={
entry:entry,
plugins:plugins
};
var baseWebpackConfig={
output:{
path:path.resolve(__dirname,'./dist'),
filename:'[name].js'
},
// cheap-module-eval-source-map is faster for development
devtool: '#cheap-module-eval-source-map',
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('app'),resolve('js'),resolve('qishi')]
},
{
test: /\.less$/,
loaders: ["style-loader", "css-loader", "postcss-loader", "less-loader"],
},
{
test: /\.css$/,
loaders: ["style-loader", "css-loader", "postcss-loader"]
},
/* {
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('img/[name].[hash:7].[ext]')
}
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
}
}*/
]
},
postcss: () => {
return [
require('precss'),
require('autoprefixer')
];
},
resolve: {
extensions: ['.js', '.json'],
alias: {
'@': resolve('js')
}
},
};
console.log(extraWebpackConfig,baseWebpackConfig);
module.exports=merge(extraWebpackConfig,baseWebpackConfig);
看一下你的以下路径是否在环境变量的path里???