Skip to content

refactor!: use EnvironmentPlugin instead of DefinePlugin #3782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const path = require('path')
const webpack = require('webpack')
const { resolveEntry, fileToComponentName } = require('./resolveWcEntry')

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

config
.plugin('web-component-options')
.use(require('webpack/lib/DefinePlugin'), [{
'process.env': {
CUSTOM_ELEMENT_NAME: JSON.stringify(libName)
}
.use(webpack.EnvironmentPlugin, [{
CUSTOM_ELEMENT_NAME: libName
}])

// enable shadow mode in vue-loader
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-service/lib/config/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ module.exports = (api, options) => {
files: assets,
options: pluginOptions
}
}, resolveClientEnv(options, true /* raw */))
}, resolveClientEnv(options))
}
}

Expand Down
8 changes: 5 additions & 3 deletions packages/@vue/cli-service/lib/config/base.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const webpack = require('webpack')

module.exports = (api, options) => {
api.chainWebpack(webpackConfig => {
const isLegacyBundle = process.env.VUE_CLI_MODERN_MODE && !process.env.VUE_CLI_MODERN_BUILD
Expand Down Expand Up @@ -142,7 +144,7 @@ module.exports = (api, options) => {
// prevent webpack from injecting useless setImmediate polyfill because Vue
// source contains it (although only uses it if it's native).
setImmediate: false,
// process is injected via DefinePlugin, although some 3rd party
// process is injected via EnvironmentPlugin, although some 3rd party
// libraries may require a mock to work properly (#934)
process: 'mock',
// prevent webpack from injecting mocks to Node native modules
Expand All @@ -156,8 +158,8 @@ module.exports = (api, options) => {

const resolveClientEnv = require('../util/resolveClientEnv')
webpackConfig
.plugin('define')
.use(require('webpack/lib/DefinePlugin'), [
.plugin('process-env')
.use(webpack.EnvironmentPlugin, [
resolveClientEnv(options)
])

Expand Down
11 changes: 1 addition & 10 deletions packages/@vue/cli-service/lib/util/resolveClientEnv.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,5 @@ module.exports = function resolveClientEnv (options, raw) {
})
env.BASE_URL = options.publicPath

if (raw) {
return env
}

for (const key in env) {
env[key] = JSON.stringify(env[key])
}
return {
'process.env': env
}
return env
}