我设法使用这个react-hot-boilerplate配置脚本来创建和测试一个简单的 React Flux webapp。
既然我有一个我喜欢的网站npm start
,那么在配置中添加生产版本的最简单/最好的方法是什么?当我使用那个“包”命令时,我想得到一个小prod
文件夹,其中包含我需要的所有最终 html 和缩小的 js 文件,这是我应该期待的吗?
这是我的package.json:
{
"name": "react-hot-boilerplate",
"version": "1.0.0",
"description": "Boilerplate for ReactJS project with hot code reloading",
"scripts": {
"start": "node server.js",
"lint": "eslint src"
},
"author": "Dan Abramov <dan.abramov@me.com> (http://github.com/gaearon)",
"license": "MIT",
"bugs": {
"url": "https://github.com/gaearon/react-hot-boilerplate/issues"
},
"homepage": "https://github.com/gaearon/react-hot-boilerplate",
"devDependencies": {
"babel-core": "^5.4.7",
"babel-eslint": "^3.1.9",
"babel-loader": "^5.1.2",
"eslint-plugin-react": "^2.3.0",
"react-hot-loader": "^1.2.7",
"webpack": "^1.9.6",
"webpack-dev-server": "^1.8.2"
},
"dependencies": {
"react": "^0.13.0",
"flux": "^2.0.2",
"events": "^1.0.2",
"object-assign": "^3.0.0",
"jquery": "^2.1.4",
"imports-loader": "^0.6.4",
"url-loader": "^0.5.6",
"numeral": "^1.5.3",
"bootstrap": "^3.3.5",
"d3": "^3.5.6",
"zeroclipboard": "^2.2.0",
"react-toastr": "^1.5.1",
"d3-legend": "^1.0.0"
}
}
我想我想在脚本列表中添加一个新脚本,以便我可以使用新npm xyz
命令,但我不确定在那里写什么。
还有我的Webpack.config.js,以防我可能(?)必须为 prod 配置使用类似但不同的副本:
var path = require('path');
var webpack = require('webpack');
module.exports = {
devtool: 'eval',
entry: [
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
'./src/index'
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/static/'
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new webpack.ProvidePlugin({ $: "jquery", jQuery: "jquery" })
],
externales: { "jquery": "jQuery", "$": 'jQuery' },
resolve: {
extensions: ['', '.js', '.jsx']
},
module: {
loaders: [
{
test: /\.jsx?$/,
loaders: ['react-hot', 'babel'],
include: path.join(__dirname, 'src')
},
{ test: /\.less$/, loader: 'style-loader!css-loader!less-loader' }, // use ! to chain loaders
{ test: /\.css$/, loader: 'style-loader!css-loader' },
{test: /\.(png|jpg|gif)$/, loader: 'url-loader?limit=8192'} // inline base64 URLs for <=8k images, direct URLs for the rest
]
}
};
如果需要副本,我不确定要保留、更改(产品配置)或添加哪些部分...