我想將我的應用程序部署到生產環境。在使用webpack -p構建我的包後,我不知道該做什麼。如何使用快遞節點服務器在生產中提供此捆綁包。使用我使用webpack編譯的express服務器將生成部署到生產-p
我webpack.config.js文件
var HtmlWebpackPlugin = require('html-webpack-plugin')
var debug = process.env.NODE_ENV !== "production";
var webpack = require("webpack");
var HTMLWebpackPluginConfig = new HtmlWebpackPlugin({
template: __dirname + '/app/index.html',
filename: 'index.html',
inject: 'body'
});
module.exports = {
devtool: debug ? "inline-sourcemap" : null,
entry: [
'./app/index.js'
],
output: {
path: __dirname + '/dist',
publicPath: '/',
filename: "index_bundle.js"
},
module: {
loaders: [
{test: /\.js$/, exclude: /node_modules/, loader: "babel-loader"}
]
},
resolve: {
extensions: ['', '.js', '.jsx']
},
plugins: debug ? [HTMLWebpackPluginConfig] : [
HTMLWebpackPluginConfig,
new webpack.optimize.CommonsChunkPlugin('common.js'),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
new webpack.optimize.AggressiveMergingPlugin()
],
};
我的package.json文件
{
"name": "my-web",
"version": "1.0.0",
"description": "Practicing react-website",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --hot --port 8080 --host 0.0.0.0 --content-base dist/ --history-api-fallback",
"prod": "NODE_ENV=production webpack -p",
"postinstall": "npm start"
},
"dependencies": {
"axios": "^0.15.0",
"express": "^4.14.0",
"radium": "^0.18.1",
"react": "^15.3.2",
"react-dom": "^15.3.2",
"react-router": "^2.8.1"
},
"devDependencies": {
"babel-core": "^6.17.0",
"babel-loader": "^6.2.5",
"babel-preset-react": "^6.16.0",
"html-webpack-plugin": "^2.22.0",
"webpack": "^1.13.2",
"webpack-dev-server": "^1.16.1"
}
}
注:NPM開始運行在本地主機上非常精細。因此,我使用webpack -p在./dist文件夾中創建捆綁包。需要從這裏的步驟。
此外,有關更好的部署方式的建議表示讚賞。
謝謝.....對於其他尋求相同的答案步驟包括 - – Vikas
編輯答案,不知道如果我能夠幫助你更多 –
你幫了很多謝謝......我甚至部署在GCP上。 – Vikas