You can install postinstall
in your package.json on the following NODE_ENV=production webpack -p
Then set start
to node
But you need to configure your web package for production by installing it in your webpack.config.js or webpack.config.js (production) file as the production configuration.
I installed everything in my webpack.config.js as follows.
const path = require('path'); const webpack = require('webpack'); const debug = process.env.NODE_ENV !== "production"; module.exports = { entry: [ './src/index.js' ], output: { path: path.resolve(__dirname, 'src'), filename: 'bundle.js' }, devtool: debug ? "inline-sourcemap" : null, module: { loader: [{ exclude: /node_modules/, loader: 'babel', query: { presets: ['angular'] } }, { test: /\.css$/, loader: "style-loader!css-loader" }] }, devServer: { historyApiFallback: true, contentBase: 'src' }, plugins: debug ? [] : [ new webpack.optimize.DedupePlugin(), new webpack.optimize.OccurenceOrderPlugin(), new webpack.optimize.UglifyJsPlugin({ mangle: {except: ['$', 'exports', 'require', 'app']}, compress: {warnings: false}, sourceMap: false }) ] }
so as soon as the command starts npm run postinstall
, the package will be generated in the directory according to webpack.config.js (output). But be sure to include the NODE_ENV=production webpack -p
commands in your package.json package before running 'npm start'. See the example below.
{ "name": "", "version": "1.0.0", "description": "", "main": "./src/bundle.js", "engines": { "node": "6.4.0" }, "scripts": { "start": "node ./src/server.js", "postinstall": "NODE_ENV=production webpack -p" }, "author": "", "license": "ISC", "dependencies": ...