-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
71 lines (61 loc) · 1.74 KB
/
webpack.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
const chalk = require('chalk');
const path = require('path');
const fs = require('fs');
const webpackBase = require('webpack');
const { application, webpack } = require('xes-webpack-core');
const app = application.getEnvApp();
const appWebpack = `./webpack.${app}.config.js`;
const factoryConfig = {
useBabelrc: true,
};
const configureWebpack = (config) => {
console.log(chalk.bold.yellow('Setting WEBPACK...'));
config.output.filename = '[name].js';
config.output.chunkFilename = '[name].js';
// This cannot be used in testing environment
if (process.env.ENV !== 'test') {
config.optimization = {
...config.optimization,
splitChunks: {
automaticNameDelimiter: '.',
chunks: 'async',
name: true,
cacheGroups: {
default: {
minSize: 120000,
minChunks: 2,
priority: -20,
reuseExistingChunk: true,
},
vendors: {
priority: -10,
test: /[\\/]node_modules[\\/]/,
},
},
},
};
}
// VIS js css
console.log(chalk.bold.yellow('Adding loader for VIS JS assets...'));
config.module.rules.push({
test: /\.(svg|png|jpg|jpeg|gif)$/,
include: path.resolve('node_modules/vis/dist'),
use: {
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'assets/vis',
},
},
});
// VIS js has broken moment use implementation
// it needs global object just to not include useless locales
config.plugins.push(new webpackBase.ContextReplacementPlugin(/moment[\/\\]locale$/, /(en|pl)$/));
return config;
};
const baseConfiguration = configureWebpack(webpack.webpackConfigFactory(factoryConfig));
if (fs.existsSync(appWebpack)) {
module.exports = (env) => require(appWebpack)(baseConfiguration);
} else {
module.exports = (env) => baseConfiguration;
}