Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
58 lines (47 loc) · 2.1 KB
/
Copy pathwebpack.config.js
File metadata and controls
58 lines (47 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const baseConfig = require('./webpack.base.config');
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const packageJson = require('./package.json');
const process = require('process');
const distPath = path.join(__dirname, packageJson.config.dist_dir_path);
// Use override value if exists, otherwise use the one defined in `package.json`
const contextRoot = process.env.CONTEXT_ROOT || packageJson.config.context_root;
// Make sure there is a trailing slash
const distUri = path.posix.join(contextRoot, packageJson.config.dist_uri, '/');
module.exports = Object.assign({}, baseConfig.webpackOptions, {
mode: 'production',
output: {
path: distPath,
publicPath: distUri,
// Using `chunkhash` instead of `hash` to ensure `vendor` and `app` have different
// computed hash. This allows `vendor` file to have longer term cache on user's browser
// until the vendor dependencies get updated
filename: 'js/[name].[chunkhash].js',
},
plugins: baseConfig.webpackOptions.plugins.concat([
new CleanWebpackPlugin(),
// To prevent the following warnings in browser console:-
// "It looks like you're using a minified copy of the development build of React.
// When deploying React apps to production, make sure to use the production build
// which skips development warnings and is faster."
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production'),
CONTEXT_ROOT: JSON.stringify(contextRoot),
APP_NAME: JSON.stringify(packageJson.name),
VERSION: JSON.stringify(packageJson.version),
},
}),
// Generates `index.html` at the location specified by the user
new HtmlWebpackPlugin(
Object.assign({}, baseConfig.htmlWebpackPluginOptions, {
filename: path.join(__dirname, packageJson.config.entry_file_path),
}),
),
// Generates GZIP compression files
new CompressionPlugin(),
]),
});