-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
50 lines (47 loc) · 1.59 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
const fs = require('fs');
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const webpackMerge = require('webpack-merge');
const baseConfig = require('@splunk/webpack-configs/base.config').default;
const TerserPlugin = require("terser-webpack-plugin");
const PROD = process.env.NODE_ENV == 'production';
// Set up an entry config by iterating over the files in the pages directory.
const entries = fs
.readdirSync(path.join(__dirname, 'src/main/webapp/pages'))
.filter((pageFile) => !/^\./.test(pageFile))
.reduce((accum, page) => {
accum[page] = path.join(__dirname, 'src/main/webapp/pages', page);
return accum;
}, {});
module.exports = webpackMerge(baseConfig, {
entry: entries,
output: {
path: path.join(__dirname, 'stage/appserver/static/pages/'),
filename: '[name].js',
},
plugins: [
new CopyWebpackPlugin({
patterns: [
{
from: path.join(__dirname, 'src/main/resources/splunk'),
to: path.join(__dirname, 'stage'),
},
],
}),
],
devtool: PROD ? "source-map" : "eval-source-map",
optimization: {
minimize: PROD,
minimizer: [new TerserPlugin()],
splitChunks: {
cacheGroups: {
commons: {
name: 'shared',
filename: '[name].bundle.js',
chunks: 'initial',
minChunks: 2
}
}
}
}
});