From 245be8dbb8ea701c400a3ad54a30fd0d54662e55 Mon Sep 17 00:00:00 2001 From: Franck Abgrall Date: Wed, 27 Nov 2019 03:55:24 +0100 Subject: [PATCH] fix($core): set NODE_ENV before creating app (#1972) --- packages/@vuepress/core/lib/index.js | 6 ++++++ packages/@vuepress/core/lib/node/App.js | 3 +-- packages/@vuepress/core/lib/node/build/index.js | 1 - 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/@vuepress/core/lib/index.js b/packages/@vuepress/core/lib/index.js index 85afa96123..09dec97807 100644 --- a/packages/@vuepress/core/lib/index.js +++ b/packages/@vuepress/core/lib/index.js @@ -10,12 +10,18 @@ function createApp (options) { } async function dev (options) { + if (process.env.NODE_ENV === undefined) { + process.env.NODE_ENV = 'development' + } const app = createApp(options) await app.process() return app.dev() } async function build (options) { + if (process.env.NODE_ENV === undefined) { + process.env.NODE_ENV = 'production' + } const app = createApp(options) await app.process() return app.build() diff --git a/packages/@vuepress/core/lib/node/App.js b/packages/@vuepress/core/lib/node/App.js index e21c8ce29b..46d6b0914b 100755 --- a/packages/@vuepress/core/lib/node/App.js +++ b/packages/@vuepress/core/lib/node/App.js @@ -38,6 +38,7 @@ module.exports = class App { */ constructor (options = {}) { + this.isProd = process.env.NODE_ENV === 'production' this.options = options this.sourceDir = this.options.sourceDir || path.join(__dirname, 'docs.fallback') logger.debug('sourceDir', this.sourceDir) @@ -459,7 +460,6 @@ module.exports = class App { */ async dev () { - this.isProd = false this.devProcess = new DevProcess(this) await this.devProcess.process() const error = await new Promise(resolve => { @@ -489,7 +489,6 @@ module.exports = class App { */ async build () { - this.isProd = true this.buildProcess = new BuildProcess(this) await this.buildProcess.process() await this.buildProcess.render() diff --git a/packages/@vuepress/core/lib/node/build/index.js b/packages/@vuepress/core/lib/node/build/index.js index b405108a32..19ffc11e6d 100644 --- a/packages/@vuepress/core/lib/node/build/index.js +++ b/packages/@vuepress/core/lib/node/build/index.js @@ -18,7 +18,6 @@ const { normalizeHeadTag, applyUserWebpackConfig } = require('../util/index') module.exports = class Build extends EventEmitter { constructor (context) { super() - process.env.NODE_ENV = 'production' this.context = context this.outDir = this.context.outDir }