-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack-common.config.js
115 lines (95 loc) · 2.64 KB
/
webpack-common.config.js
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//
// Copyright 2019 DXOS.org
//
const path = require('path');
const Dotenv = require('dotenv-webpack');
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin")
const VersionFile = require('webpack-version-file-plugin');
const webpack = require('webpack');
const PUBLIC_URL = process.env.PUBLIC_URL || '';
const CONFIG_FILE = path.relative('./src', process.env.CONFIG_FILE || 'config-local.yml');
module.exports = {
devtool: 'eval-source-map',
watchOptions: {
ignored: /node_modules/,
aggregateTimeout: 600
},
devServer: {
static: {
directory: path.join(__dirname, "dist")
},
compress: true,
allowedHosts: "all",
port: 8080
},
resolve: {
fallback: {
fs: false
}
},
output: {
path: `${__dirname}/dist/production`,
filename: '[name].bundle.js',
publicPath: PUBLIC_URL
},
optimization: {
runtimeChunk: 'single',
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
minSize: 0,
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name (module) {
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
if (packageName.startsWith('@cerc-io')) {
return 'cerc-io';
}
if (packageName.startsWith('@material-ui')) {
return 'material-ui';
}
return 'vendor';
}
}
}
}
},
plugins: [
// https://www.npmjs.com/package/dotenv-webpack#properties
new Dotenv({
path: process.env.DOT_ENV || '.env'
}),
// NOTE: Must be defined below Dotenv (otherwise will override).
// https://webpack.js.org/plugins/environment-plugin
// new webpack.EnvironmentPlugin({}),
// Define the build config file based on the target.
// https://webpack.js.org/plugins/normal-module-replacement-plugin
new webpack.NormalModuleReplacementPlugin(/(.*)__CONFIG_FILE__/, (resource) => {
resource.request = resource.request.replace(/__CONFIG_FILE__/, CONFIG_FILE);
}),
// https://www.npmjs.com/package/webpack-version-file-plugin
new VersionFile({
template: path.join(__dirname, 'version.ejs'),
packageFile: path.join(__dirname, 'package.json'),
outputFile: path.join(__dirname, 'src', 'version.json')
}),
new NodePolyfillPlugin()
],
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader'
}
},
// https://github.com/eemeli/yaml-loader
{
test: /\.ya?ml$/,
use: 'yaml-loader'
}
]
}
};