webpack run server code example

Example 1: webpack dev server

devServer: {
		open: true,
		compress: true,
		hot: true,
		inline: true,
		watchContentBase: true,
		contentBase: resolve(process.cwd(), 'build'),
		historyApiFallback: true,
		before: (app, server, compiler) => {
			const fileExist = existsSync('./src/setupProxyx.js')
			if (fileExist) {
				const pathProxy = resolve(process.cwd(), 'src/setupProxy')
				return require(`${pathProxy}`)(app)
			}
		},
		port: process.env.PORT || 3000,
		liveReload: false
	},

Example 2: webpack dev server

devServer: {
		open: true,
		compress: true,
		hot: true,
		inline: true,
		watchContentBase: true,
		contentBase: resolve(process.cwd(), 'build'),
		historyApiFallback: true,
		before: (app, server, compiler) => {
			const fileExist = existsSync('./src/setupProxy.js')
			if (fileExist) {
				const pathProxy = resolve(process.cwd(), 'src/setupProxy')
				return require(`${pathProxy}`)(app)
			}
		},
		port: process.env.PORT || 3000,
		liveReload: false
	},

Example 3: running webpack application on production server

"scripts": {
    "build": "NODE_ENV=production webpack --config ./webpack.production.config.js"
},

Example 4: running webpack application on production server

new webpack.optimize.CommonsChunkPlugin('common.js'),
  new webpack.optimize.DedupePlugin(),
  new webpack.optimize.UglifyJsPlugin(),
  new webpack.optimize.AggressiveMergingPlugin()