Skip to content

Commit

Permalink
feat(docz-core): add sourcemap config argument
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Dec 17, 2018
1 parent 61a3050 commit 3baad4a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
5 changes: 5 additions & 0 deletions packages/docz-core/src/commands/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export interface Argv {
websocketHost: string
native: boolean
codeSandbox: boolean
sourcemaps: boolean
/* template args */
title: string
description: string
Expand Down Expand Up @@ -198,4 +199,8 @@ export const args = (env: Env) => (yargs: any) => {
type: 'boolean',
default: getEnv('docz.codeSandbox', true),
})
yargs.positional('sourcemaps', {
type: 'boolean',
default: getEnv('docz.sourcemaps', true),
})
}
5 changes: 2 additions & 3 deletions packages/docz-core/src/webpack/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const createConfig = (args: Args, env: Env) => async (
* loaders
*/

loaders.sourceMaps(config, args)
config.when(args.sourcemaps, cfg => loaders.sourceMaps(cfg, args))
loaders.js(config, args)
loaders.mdx(config, args)
loaders.images(config)
Expand Down Expand Up @@ -170,9 +170,8 @@ export const createConfig = (args: Args, env: Env) => async (
},
})

config.when(isProd, cfg => minifier(cfg))
config.performance.hints(false)

config.when(isProd, cfg => minifier(cfg, args))
hooks.onCreateWebpackChain<Config>(config, !isProd, args)
args.onCreateWebpackChain<Config>(config, !isProd, args)

Expand Down
8 changes: 5 additions & 3 deletions packages/docz-core/src/webpack/minifier.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Config from 'webpack-chain'
import * as TerserPlugin from 'terser-webpack-plugin'

export const minifier = (config: Config) => {
import { Config as Args } from '../commands/args'

export const minifier = (config: Config, args: Args) => {
config.optimization.minimizer('js').use(TerserPlugin, [
{
terserOptions: {
Expand All @@ -22,9 +24,9 @@ export const minifier = (config: Config) => {
ascii_only: true,
},
},
cache: true,
parallel: true,
sourceMap: true,
cache: !args.debug,
sourceMap: args.sourcemaps,
},
])
}

0 comments on commit 3baad4a

Please sign in to comment.