UNPKG

2.08 kBPlain TextView Raw
1import * as TerserPlugin from 'terser-webpack-plugin'
2import Berun from '@berun/berun'
3
4/**
5 * Add Development and Production config to berun.webpack.optimization
6 */
7export const optimization = (berun: Berun, _) => {
8 berun.webpack.optimization
9 .splitChunks({ chunks: 'all', name: false })
10 .runtimeChunk(true)
11}
12
13/**
14 * Add Development and Production config to berun.webpack.optimization
15 */
16export const terser = (berun: Berun, _) => {
17 const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false'
18
19 berun.webpack.optimization.minimize(true)
20
21 berun.webpack.optimization.minimizer('terser').use(TerserPlugin, [
22 {
23 terserOptions: {
24 parse: {
25 // we want terser to parse ecma 8 code. However, we don't want it
26 // to apply any minfication steps that turns valid ecma 5 code
27 // into invalid ecma 5 code. This is why the 'compress' and 'output'
28 // sections only apply transformations that are ecma 5 safe
29 // https://github.com/facebook/create-react-app/pull/4234
30 ecma: 8
31 },
32 compress: {
33 ecma: 5,
34 warnings: false,
35 // Disabled because of an issue with Uglify breaking seemingly valid code:
36 // https://github.com/facebook/create-react-app/issues/2376
37 // Pending further investigation:
38 // https://github.com/mishoo/UglifyJS2/issues/2011
39 comparisons: false
40 },
41 mangle: {
42 safari10: true
43 },
44 output: {
45 ecma: 5,
46 comments: false,
47 // Turned on because emoji and regex is not minified properly using default
48 // https://github.com/facebook/create-react-app/issues/2488
49 // eslint-disable-next-line @typescript-eslint/camelcase
50 ascii_only: true
51 }
52 },
53 // Use multi-process parallel running to improve the build speed
54 // Default number of concurrent runs: os.cpus().length - 1
55 parallel: true,
56 // Enable file caching
57 cache: true,
58 sourceMap: shouldUseSourceMap
59 }
60 ])
61}