Skip to content

Commit 282d1f9

Browse files
authored
refactor!: use EnvironmentPlugin instead of DefinePlugin (#3782)
BREAKING CHANGE: This change breaks use cases where users have tapped the `define` plugin options in `chainWebpack` fixes #3579
1 parent 3907d22 commit 282d1f9

File tree

4 files changed

+10
-18
lines changed

4 files changed

+10
-18
lines changed

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

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

45
module.exports = (api, { target, entry, name }) => {
@@ -62,10 +63,8 @@ module.exports = (api, { target, entry, name }) => {
6263

6364
config
6465
.plugin('web-component-options')
65-
.use(require('webpack/lib/DefinePlugin'), [{
66-
'process.env': {
67-
CUSTOM_ELEMENT_NAME: JSON.stringify(libName)
68-
}
66+
.use(webpack.EnvironmentPlugin, [{
67+
CUSTOM_ELEMENT_NAME: libName
6968
}])
7069

7170
// 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
@@ -88,7 +88,7 @@ module.exports = (api, options) => {
8888
files: assets,
8989
options: pluginOptions
9090
}
91-
}, resolveClientEnv(options, true /* raw */))
91+
}, resolveClientEnv(options))
9292
}
9393
}
9494

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

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

168170
const resolveClientEnv = require('../util/resolveClientEnv')
169171
webpackConfig
170-
.plugin('define')
171-
.use(require('webpack/lib/DefinePlugin'), [
172+
.plugin('process-env')
173+
.use(webpack.EnvironmentPlugin, [
172174
resolveClientEnv(options)
173175
])
174176

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

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

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-
}
12+
return env
2213
}

0 commit comments

Comments
 (0)