From c932991ddb1230db47bd236c20f165b6c1e7920d Mon Sep 17 00:00:00 2001 From: Franck Date: Wed, 23 Oct 2019 12:05:18 +0200 Subject: [PATCH 1/4] fix($core): Set production mode before creating VuePress app on build mode --- packages/@vuepress/core/lib/index.js | 1 + packages/@vuepress/core/lib/node/build/index.js | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@vuepress/core/lib/index.js b/packages/@vuepress/core/lib/index.js index 85afa96123..15206b07ba 100644 --- a/packages/@vuepress/core/lib/index.js +++ b/packages/@vuepress/core/lib/index.js @@ -16,6 +16,7 @@ async function dev (options) { } async function build (options) { + process.env.NODE_ENV = 'production' const app = createApp(options) await app.process() return app.build() 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 } From 2e79ab5fda82236d3e83f40e1eb96d99752c0190 Mon Sep 17 00:00:00 2001 From: Franck Date: Wed, 30 Oct 2019 17:37:30 +0100 Subject: [PATCH 2/4] feat: Set NODE_ENV to 'development' when using dev command --- packages/@vuepress/core/lib/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/@vuepress/core/lib/index.js b/packages/@vuepress/core/lib/index.js index 15206b07ba..56a76aad8f 100644 --- a/packages/@vuepress/core/lib/index.js +++ b/packages/@vuepress/core/lib/index.js @@ -10,6 +10,7 @@ function createApp (options) { } async function dev (options) { + process.env.NODE_ENV = 'development' const app = createApp(options) await app.process() return app.dev() From 5b6506a835504d3bc4cfa536cc142e6acce47949 Mon Sep 17 00:00:00 2001 From: meteorlxy Date: Wed, 27 Nov 2019 10:09:49 +0800 Subject: [PATCH 3/4] fix($core): merge #2028 --- packages/@vuepress/core/lib/node/App.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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() From 3614eb54d0eb6f6bdc630726a36a96b497bbd114 Mon Sep 17 00:00:00 2001 From: meteorlxy Date: Wed, 27 Nov 2019 10:28:32 +0800 Subject: [PATCH 4/4] fix: avoid overwriting NODE_ENV --- packages/@vuepress/core/lib/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/@vuepress/core/lib/index.js b/packages/@vuepress/core/lib/index.js index 56a76aad8f..09dec97807 100644 --- a/packages/@vuepress/core/lib/index.js +++ b/packages/@vuepress/core/lib/index.js @@ -10,14 +10,18 @@ function createApp (options) { } async function dev (options) { - process.env.NODE_ENV = 'development' + 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) { - process.env.NODE_ENV = 'production' + if (process.env.NODE_ENV === undefined) { + process.env.NODE_ENV = 'production' + } const app = createApp(options) await app.process() return app.build()