-
Notifications
You must be signed in to change notification settings - Fork 17
/
dist.config.ts
53 lines (45 loc) · 1.45 KB
/
dist.config.ts
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
import BundleAnalyzerPlugin from '@dojo/webpack-contrib/webpack-bundle-analyzer/BundleAnalyzerPlugin';
import baseConfigFactory from './base.config';
import webpack = require('webpack');
import * as path from 'path';
import * as CleanWebpackPlugin from 'clean-webpack-plugin';
import * as WebpackChunkHash from 'webpack-chunk-hash';
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
function webpackConfig(args: any): webpack.Configuration {
const config = baseConfigFactory(args);
const { plugins, output } = config;
const location = path.join('dist', args.element.name);
const outputPath = output!.path as string;
config.mode = 'production';
config.optimization = {
...config.optimization,
minimizer: [
new TerserPlugin({ sourceMap: true, cache: true }),
new OptimizeCssAssetsPlugin({
cssProcessor: require('cssnano'),
cssProcessorPluginOptions: {
preset: ['default', { calc: false }]
}
})
]
};
config.plugins = [
...plugins!,
new BundleAnalyzerPlugin({
analyzerMode: 'static',
openAnalyzer: false,
generateStatsFile: true,
reportFilename: '../info/report.html',
statsFilename: '../info/stats.json'
}),
new WebpackChunkHash(),
new CleanWebpackPlugin([location], { root: outputPath, verbose: false })
];
config.output = {
...output,
path: path.join(outputPath, location)
};
return config;
}
export default webpackConfig;