var debug = process.env.NODE_ENV !== "production";
var webpack = require('webpack');
var path = require('path');
module.exports = {
entry: "./src/js/root.js",
context: path.join(__dirname),
devtool: debug ? "inline-sourcemap" : null,
output: {
// path: __dirname,
filename: "./src/bundle.js"
},
module: {
loaders: [
{
test: /\.js?$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['react', 'es2015'],
plugins: ['react-html-attrs'], //添加组件的插件配置
}
},
//下面是使用 ant-design 的配置文件
{ test: /\.css$/, loader: 'style-loader!css-loader' }
]
},
plugins: debug ? [] : [
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
],
externals: {
//don't bundle the 'react' npm package with our bundle.js
//but get it from a global 'React' variable
'react': 'React'
},
resolve: {
extensions: ['', '.js', '.jsx'],
modulesDirectories: ["./src", "node_modules", "bower_components"]
}
};想问一个react 的问题,不知道是哪里错了。改了无数次都没用,路径看着也没毛病。但是换了别人的node_module就可以了。重新安装新的插件就又这样,有谁可以帮忙看看?
1 回答
ruibin
TA贡献358条经验 获得超213个赞
很可能是你运行路径的问题,你可以在你webpack.config.js文件里面打印process.cwd()。万能的修正方法是把相对路径别变成绝对路径。const path = require('path'); entry: path.resolve(__dirname, './src/js/root.js')
添加回答
举报
0/150
提交
取消