当我运行webpack时 - 我收到了Cannot resolve module 'js/app.js'
的错误。当我npm run dev
时,我的app.min.js没有遵守。
我创建了一个git repo,这是我的webpack.config.js
var debug = process.env.NODE_ENV !== "production";
var webpack = require('webpack');
var path = require('path');
module.exports = {
context: path.join(__dirname, "src"),
devtool: debug ? "inline-sourcemap" : null,
entry: "js/app.js", //what's wrong with this line?
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
query: {
presets: ['react', 'es2015', 'stage-0'] }
}
]
},
output: {
path: __dirname + "src",
filename: "app.min.js" //this is not even complied?
},
plugins: debug ? [] : [
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
],
};
答案 0 :(得分:1)
使用context
时,the entry
path should start with a ./
后跟条目文件的相对路径。
module.exports = {
context: path.join(__dirname, "src"),
devtool: debug ? "inline-sourcemap" : null,
entry: "./js/app.js",
...
}
解决此问题的另一种方法是不使用context
密钥并在entry
密钥中设置绝对路径,如下所示:
entry: path.join(__dirname, 'src/js/app.js')