[英]how to set u a react/node project with babel and webpack?
i'm tryng to setup a new react project with babel and webpack but it's not working. 我正在尝试使用babel和webpack设置一个新的react项目,但是它不起作用。 this is my webpack.dev.config.js file : 这是我的webpack.dev.config.js文件:
var webpack = require('webpack');
var path = require('path');
var parentDir = path.join(__dirname, '../');
module.exports = {
entry: [
path.join(parentDir, '/react_components/index.js')
],
module: {
loaders: [{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['es2015', 'react']
}
}
]
},
output: {
path: parentDir + '/html',
filename: 'main.js'
},
devServer: {
contentBase: parentDir,
historyApiFallback: true
}
}
and this is a screen shot from my project : 这是我的项目的屏幕截图:
i get the message that webpack is compiled successfully but the main.js file remain empty 我收到消息说webpack已成功编译,但main.js文件仍然为空
PS : i'm using this tutorial PS:我正在使用本教程
https://medium.com/netscape/setting-up-a-react-project-from-scratch-d62f38ab6d97 https://medium.com/netscape/setting-up-a-react-project-from-scratch-d62f38ab6d97
Try running node node_modules\\webpack\\bin\\webpack.js
in project directory and it should build a phyisical main.js file. 尝试在项目目录中运行node node_modules\\webpack\\bin\\webpack.js
,它将建立一个物理的main.js文件。
The webpack-dev-server doesn't write to disk. webpack-dev-server不会写入磁盘。 It serves the result from memory. 它从内存提供结果。
Source: https://github.com/webpack/webpack-dev-server/issues/24 来源: https : //github.com/webpack/webpack-dev-server/issues/24
Open package.json file. 打开package.json文件。 Inside scripts add "build": "webpack"
在内部脚本中添加"build": "webpack"
Your scripts object should essentially look something like this : 您的脚本对象本质上应该看起来像这样:
"scripts": { "test": "echo \\"Error: no test specified\\" && exit 1", "start": "webpack-dev-server --hot", "build":"webpack" }
then run npm run build
on your terminal. 然后在终端上运行npm run build
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.