From 615aa1fbb6e4dca022148ef0ac13fce5236e19e5 Mon Sep 17 00:00:00 2001 From: Pedro Nauck Date: Fri, 22 Jun 2018 03:06:14 -0300 Subject: [PATCH] fix(docz-core): node env for production --- packages/docz-core/src/Bundler.ts | 10 ++++++---- packages/docz-core/src/bundlers/webpack/config.ts | 3 ++- packages/docz-core/src/commands/build.ts | 3 +++ packages/docz-core/src/commands/dev.ts | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/docz-core/src/Bundler.ts b/packages/docz-core/src/Bundler.ts index 9696999c5..c287679b6 100644 --- a/packages/docz-core/src/Bundler.ts +++ b/packages/docz-core/src/Bundler.ts @@ -20,8 +20,6 @@ export interface BundlerConstructor { build: BuildFn } -const IS_PROD = process.env.NODE_ENV === 'production' - export class Bundler { private readonly args: Args private config: C @@ -39,7 +37,7 @@ export class Bundler { 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 { @@ -54,6 +52,10 @@ export class Bundler { const { plugins } = this.args const reduce = Plugin.reduceFromPlugins(plugins) - return reduce('modifyBundlerConfig', config, !IS_PROD) + return reduce('modifyBundlerConfig', config, !this.isProd()) + } + + private isProd(): boolean { + return process.env.NODE_ENV === 'production' } } diff --git a/packages/docz-core/src/bundlers/webpack/config.ts b/packages/docz-core/src/bundlers/webpack/config.ts index 2d0d43039..7d6edbc3b 100644 --- a/packages/docz-core/src/bundlers/webpack/config.ts +++ b/packages/docz-core/src/bundlers/webpack/config.ts @@ -92,7 +92,7 @@ export const createConfig = (babelrc: BabelRC) => ( config.merge({ optimization: { - nodeEnv: 'dev', + nodeEnv: env, namedModules: true, noEmitOnErrors: true, runtimeChunk: true, @@ -101,6 +101,7 @@ export const createConfig = (babelrc: BabelRC) => ( name: 'vendors', }, ...(isProd && { + minimize: true, minimizer: [uglify], }), }, diff --git a/packages/docz-core/src/commands/build.ts b/packages/docz-core/src/commands/build.ts index 394832888..d1ce21ea8 100644 --- a/packages/docz-core/src/commands/build.ts +++ b/packages/docz-core/src/commands/build.ts @@ -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') diff --git a/packages/docz-core/src/commands/dev.ts b/packages/docz-core/src/commands/dev.ts index 2246cf67f..468ce96ed 100644 --- a/packages/docz-core/src/commands/dev.ts +++ b/packages/docz-core/src/commands/dev.ts @@ -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'