我已经从https://www.tutorialspoint.com/reactjs/reactjsjsx.htm创建了一个基本的React应用程序。这里,我想在基于Apache的服务器上运行这个测试代码,我知道我需要创建一个可分发的构建,但我不知道如何做到这一点,也找不到清晰的说明。
我在Apache服务器上看到过这篇文章React,js,但它没有什么更多的指导方针
以下是web包配置文件的外观检查指定的dist dir和输出文件。我错过了指定dist目录路径的方法
const webpack = require('webpack');
const path = require('path');
var config = {
entry: './main.js',
output: {
path: path.join(__dirname, '/dist'),
filename: 'index.js',
},
devServer: {
inline: true,
port: 8080
},
resolveLoader: {
modules: [path.join(__dirname, 'node_modules')]
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['es2015', 'react']
}
}
]
},
}
module.exports = config;
则包json文件
{
"name": "reactapp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack --progress",
"production": "webpack -p --progress"
},
"author": "",
"license": "ISC",
"dependencies": {
"react": "^15.4.2",
"react-dom": "^15.4.2",
"webpack": "^2.2.1"
},
"devDependencies": {
"babel-core": "^6.0.20",
"babel-loader": "^6.0.1",
"babel-preset-es2015": "^6.0.15",
"babel-preset-react": "^6.0.15",
"babel-preset-stage-0": "^6.0.15",
"express": "^4.13.3",
"webpack": "^1.9.6",
"webpack-devserver": "0.0.6"
}
}
请注意script部分和production部分,production部分为您提供了最终的可部署index.js文件(名称可以是任何内容)
其余的事情将取决于您的代码和组件
执行以下命令序列
npm安装
这将使您获得所有的依赖关系(节点模块)
然后
npm运行生产
这将得到最终的index.js
文件,该文件将包含绑定的所有代码
完成后,将index.html
和index.js
文件放在www/html或web app根目录下,仅此而已。