Skip to content

Commit f5a1950

Browse files
committed
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 f553eb7 commit f5a1950

File tree

4 files changed

+12
-17
lines changed

4 files changed

+12
-17
lines changed

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

+3-4
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

+1-1
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

+7-2
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,6 +155,9 @@ 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,
158+
// process is injected via EnvironmentPlugin, although some 3rd party
159+
// libraries may require a mock to work properly (#934)
160+
process: 'mock',
156161
// prevent webpack from injecting mocks to Node native modules
157162
// that does not make sense for the client
158163
dgram: 'empty',
@@ -164,8 +169,8 @@ module.exports = (api, options) => {
164169

165170
const resolveClientEnv = require('../util/resolveClientEnv')
166171
webpackConfig
167-
.plugin('define')
168-
.use(require('webpack/lib/DefinePlugin'), [
172+
.plugin('process-env')
173+
.use(webpack.EnvironmentPlugin, [
169174
resolveClientEnv(options)
170175
])
171176

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

+1-10
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)