webpackconfiguration错误无法parsing模块

当我运行webpack – watch我得到了Cannot resolve module 'js/app.js' 。 然后,当我执行npm run dev时,我的app.min.js没有编译。

我创build了一个git仓库,这是我的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 }), ], }; 

使用contextentrypath应以./开头,后跟入口文件的相对path。

 module.exports = { context: path.join(__dirname, "src"), devtool: debug ? "inline-sourcemap" : null, entry: "./js/app.js", ... } 

解决这个问题的另一种方法是不使用context键,并在entry键中有一个绝对path,如下所示:

 entry: path.join(__dirname, 'src/js/app.js')