Skip to content

Commit 01e36f3

Browse files
authored
refactor!: use DefinePlugin (again) instead of EnvironmentPlugin (#4673)
* Revert "refactor: use EnvironmentPlugin instead of DefinePlugin" This reverts commit 7117a09. * refactor: use the exported DefinePlugin
1 parent 5c2d0ba commit 01e36f3

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

packages/@vue/cli-service/lib/commands/build/resolveWcConfig.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const path = require('path')
2-
const webpack = require('webpack')
32
const { resolveEntry, fileToComponentName } = require('./resolveWcEntry')
43

54
module.exports = (api, { target, entry, name, 'inline-vue': inlineVue }) => {
@@ -56,8 +55,8 @@ module.exports = (api, { target, entry, name, 'inline-vue': inlineVue }) => {
5655

5756
config
5857
.plugin('web-component-options')
59-
.use(webpack.EnvironmentPlugin, [{
60-
CUSTOM_ELEMENT_NAME: libName
58+
.use(require('webpack').DefinePlugin, [{
59+
'process.env.CUSTOM_ELEMENT_NAME': JSON.stringify(libName)
6160
}])
6261

6362
// enable shadow mode in vue-loader

packages/@vue/cli-service/lib/config/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ module.exports = (api, options) => {
9898
files: assets,
9999
options: pluginOptions
100100
}
101-
}, resolveClientEnv(options))
101+
}, resolveClientEnv(options, true /* raw */))
102102
}
103103
}
104104

packages/@vue/cli-service/lib/config/base.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const webpack = require('webpack')
2-
31
module.exports = (api, options) => {
42
api.chainWebpack(webpackConfig => {
53
const isLegacyBundle = process.env.VUE_CLI_MODERN_MODE && !process.env.VUE_CLI_MODERN_BUILD
@@ -155,7 +153,7 @@ module.exports = (api, options) => {
155153
// prevent webpack from injecting useless setImmediate polyfill because Vue
156154
// source contains it (although only uses it if it's native).
157155
setImmediate: false,
158-
// process is injected via EnvironmentPlugin, although some 3rd party
156+
// process is injected via DefinePlugin, although some 3rd party
159157
// libraries may require a mock to work properly (#934)
160158
process: 'mock',
161159
// prevent webpack from injecting mocks to Node native modules
@@ -169,8 +167,8 @@ module.exports = (api, options) => {
169167

170168
const resolveClientEnv = require('../util/resolveClientEnv')
171169
webpackConfig
172-
.plugin('process-env')
173-
.use(webpack.EnvironmentPlugin, [
170+
.plugin('define')
171+
.use(require('webpack').DefinePlugin, [
174172
resolveClientEnv(options)
175173
])
176174

packages/@vue/cli-service/lib/util/resolveClientEnv.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,14 @@ module.exports = function resolveClientEnv (options, raw) {
99
})
1010
env.BASE_URL = options.publicPath
1111

12-
return env
12+
if (raw) {
13+
return env
14+
}
15+
16+
for (const key in env) {
17+
env[key] = JSON.stringify(env[key])
18+
}
19+
return {
20+
'process.env': env
21+
}
1322
}

0 commit comments

Comments
 (0)