Skip to content

Commit

Permalink
fix(docz-core): webpack chain minimizer config
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Oct 30, 2018
1 parent 7f05dbf commit ab13208
Showing 1 changed file with 37 additions and 40 deletions.
77 changes: 37 additions & 40 deletions packages/docz-core/src/bundlers/webpack/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { minify } from 'html-minifier'
import miniHtmlWebpack from 'mini-html-webpack-plugin'
import friendlyErrors from 'friendly-errors-webpack-plugin'
import manifestPlugin from 'webpack-manifest-plugin'
import TerserPlugin from 'terser-webpack-plugin'
import * as TerserPlugin from 'terser-webpack-plugin'

import * as loaders from './loaders'
import * as paths from '../../config/paths'
Expand All @@ -15,30 +15,6 @@ import { Config as Args, Env } from '../../commands/args'
import { BabelRC } from '../../utils/babel-config'
import { parseHtml, htmlTemplate } from '../../utils/parse-html'

const terser = new TerserPlugin({
terserOptions: {
parse: {
ecma: 8,
},
compress: {
ecma: 5,
warnings: false,
comparisons: false,
},
mangle: {
safari10: true,
},
output: {
ecma: 5,
comments: false,
ascii_only: true,
},
},
parallel: true,
cache: true,
sourceMap: true,
})

export const createConfig = (args: Args, env: Env) => async (
babelrc: BabelRC
): Promise<Configuration> => {
Expand Down Expand Up @@ -93,22 +69,43 @@ export const createConfig = (args: Args, env: Env) => async (
* optimization
*/

config.merge({
optimization: {
runtimeChunk: true,
nodeEnv: env,
namedModules: true,
noEmitOnErrors: true,
splitChunks: {
chunks: 'all',
name: 'vendors',
config.optimization
.runtimeChunk(true)
.nodeEnv(env)
.namedModules(true)
.splitChunks({ chunks: 'all', name: 'vendors' })
.minimize(isProd)

/** TODO: this is needed because incorrect typing on webpack-chain */
const optimization: any = config.optimization

if (isProd) {
optimization.minimizer('js').use(TerserPlugin, [
{
terserOptions: {
parse: {
ecma: 8,
},
compress: {
ecma: 5,
warnings: false,
comparisons: false,
},
mangle: {
safari10: true,
},
output: {
ecma: 5,
comments: false,
ascii_only: true,
},
},
parallel: true,
cache: true,
sourceMap: true,
},
...(isProd && {
minimize: true,
minimizer: [terser],
}),
},
})
])
}

/**
* entries
Expand Down

0 comments on commit ab13208

Please sign in to comment.