Webpack code example

Example 1: webpack merge

npm install --save-dev webpack-merge

const { merge } = require('webpack-merge');

Example 2: install webpack

npm install --save-dev webpack
# or specific version
npm install --save-dev webpack@<version>

Example 3: webpack config example

npm install --save-dev webpack-dev-server

Example 4: 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 5: npm webpack

yarn add webpack --dev