Skip to content

Commit

Permalink
fix(docz-core): node env for production
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Jun 22, 2018
1 parent 5973969 commit 615aa1f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
10 changes: 6 additions & 4 deletions packages/docz-core/src/Bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ export interface BundlerConstructor<Config> {
build: BuildFn<Config>
}

const IS_PROD = process.env.NODE_ENV === 'production'

export class Bundler<C = any> {
private readonly args: Args
private config: C
Expand All @@ -39,7 +37,7 @@ export class Bundler<C = any> {

public getConfig(): C {
const config = this.mountConfig(this.config)
return this.args.modifyBundlerConfig(config, !IS_PROD)
return this.args.modifyBundlerConfig(config, !this.isProd())
}

public async createServer(config: C): Promise<BundlerServer> {
Expand All @@ -54,6 +52,10 @@ export class Bundler<C = any> {
const { plugins } = this.args
const reduce = Plugin.reduceFromPlugins<C>(plugins)

return reduce('modifyBundlerConfig', config, !IS_PROD)
return reduce('modifyBundlerConfig', config, !this.isProd())
}

private isProd(): boolean {
return process.env.NODE_ENV === 'production'
}
}
3 changes: 2 additions & 1 deletion packages/docz-core/src/bundlers/webpack/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const createConfig = (babelrc: BabelRC) => (

config.merge({
optimization: {
nodeEnv: 'dev',
nodeEnv: env,
namedModules: true,
noEmitOnErrors: true,
runtimeChunk: true,
Expand All @@ -101,6 +101,7 @@ export const createConfig = (babelrc: BabelRC) => (
name: 'vendors',
},
...(isProd && {
minimize: true,
minimizer: [uglify],
}),
},
Expand Down
3 changes: 3 additions & 0 deletions packages/docz-core/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { Entries } from '../Entries'
import { Config } from './args'
import { Plugin } from '../Plugin'

process.env.BABEL_ENV = process.env.BABEL_ENV || 'production'
process.env.NODE_ENV = process.env.NODE_ENV || 'production'

export const build = async (args: Config) => {
const config = loadConfig(args)
const bundler = webpack(config, 'production')
Expand Down
2 changes: 1 addition & 1 deletion packages/docz-core/src/commands/dev.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logger from 'signale'
import * as fs from 'fs-extra'
import logger from 'signale'
import detectPort from 'detect-port'

import * as paths from '../config/paths'
Expand Down

0 comments on commit 615aa1f

Please sign in to comment.