Skip to content

Commit 88313fd

Browse files
authored
refactor: remove redundant Webpack version checks (#6638)
1 parent 2f16677 commit 88313fd

File tree

4 files changed

+16
-49
lines changed

4 files changed

+16
-49
lines changed

Diff for: packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js

+6-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const HtmlWebpackPlugin = require('html-webpack-plugin')
2-
const { semver } = require('@vue/cli-shared-utils')
32

43
const ID = 'vue-cli:pwa-html-plugin'
54

@@ -203,24 +202,12 @@ module.exports = class HtmlPwaPlugin {
203202
size: () => outputManifest.length
204203
}
205204

206-
let webpackMajor = 4
207-
if (compiler.webpack) {
208-
webpackMajor = semver.major(compiler.webpack.version)
209-
}
210-
211-
if (webpackMajor === 4) {
212-
compiler.hooks.emit.tapAsync(ID, (data, cb) => {
213-
data.assets[manifestPath] = manifestAsset
214-
cb(null, data)
215-
})
216-
} else {
217-
compiler.hooks.compilation.tap(ID, compilation => {
218-
compilation.hooks.processAssets.tap(
219-
{ name: ID, stage: 'PROCESS_ASSETS_STAGE_ADDITIONS' },
220-
assets => { assets[manifestPath] = manifestAsset }
221-
)
222-
})
223-
}
205+
compiler.hooks.compilation.tap(ID, compilation => {
206+
compilation.hooks.processAssets.tap(
207+
{ name: ID, stage: 'PROCESS_ASSETS_STAGE_ADDITIONS' },
208+
assets => { assets[manifestPath] = manifestAsset }
209+
)
210+
})
224211
}
225212
}
226213
}

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

+2-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = (api, { target, entry, name, 'inline-vue': inlineVue }) => {
55
// Disable CSS extraction and turn on CSS shadow mode for vue-style-loader
66
process.env.VUE_CLI_CSS_SHADOW_MODE = true
77

8-
const { log, error, semver } = require('@vue/cli-shared-utils')
8+
const { log, error } = require('@vue/cli-shared-utils')
99
const abort = msg => {
1010
log()
1111
error(msg)
@@ -14,7 +14,6 @@ module.exports = (api, { target, entry, name, 'inline-vue': inlineVue }) => {
1414

1515
const cwd = api.getCwd()
1616
const webpack = require('webpack')
17-
const webpackMajor = semver.major(webpack.version)
1817
const vueMajor = require('../../util/getVueMajor')(cwd)
1918
if (vueMajor === 3) {
2019
abort(`Vue 3 support of the web component target is still under development.`)
@@ -131,11 +130,7 @@ module.exports = (api, { target, entry, name, 'inline-vue': inlineVue }) => {
131130

132131
// to ensure that multiple copies of async wc bundles can co-exist
133132
// on the same page.
134-
if (webpackMajor === 4) {
135-
rawConfig.output.jsonpFunction = libName.replace(/-\w/g, c => c.charAt(1).toUpperCase()) + '_jsonp'
136-
} else {
137-
rawConfig.output.uniqueName = `vue-lib-${libName}`
138-
}
133+
rawConfig.output.uniqueName = `vue-lib-${libName}`
139134

140135
return rawConfig
141136
}

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

+4-15
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,10 @@ module.exports = (api, options) => {
3333
.filename(outputFilename)
3434
.chunkFilename(outputFilename)
3535

36-
const webpack = require('webpack')
37-
const { semver } = require('@vue/cli-shared-utils')
38-
const webpackMajor = semver.major(webpack.version)
39-
if (webpackMajor !== 4) {
40-
// FIXME: a temporary workaround to get accurate contenthash in `applyLegacy`
41-
// Should use a better fix per discussions at <https://github.com/jantimon/html-webpack-plugin/issues/1554#issuecomment-753653580>
42-
webpackConfig.optimization
43-
.set('realContentHash', false)
44-
}
36+
// FIXME: a temporary workaround to get accurate contenthash in `applyLegacy`
37+
// Should use a better fix per discussions at <https://github.com/jantimon/html-webpack-plugin/issues/1554#issuecomment-753653580>
38+
webpackConfig.optimization
39+
.set('realContentHash', false)
4540

4641
// code splitting
4742
if (process.env.NODE_ENV !== 'test') {
@@ -72,13 +67,7 @@ module.exports = (api, options) => {
7267
scriptLoading: 'defer',
7368
templateParameters: (compilation, assets, assetTags, pluginOptions) => {
7469
// enhance html-webpack-plugin's built in template params
75-
let stats
7670
return Object.assign({
77-
// make stats lazy as it is expensive
78-
// TODO: not sure if it's still needed as of <https://github.com/jantimon/html-webpack-plugin/issues/780#issuecomment-390651831>
79-
get webpack () {
80-
return stats || (stats = compilation.getStats().toJson())
81-
},
8271
compilation: compilation,
8372
webpackConfig: compilation.options,
8473
htmlWebpackPlugin: {

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

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
const path = require('path')
2-
const { semver } = require('@vue/cli-shared-utils')
32

43
/** @type {import('@vue/cli-service').ServicePlugin} */
54
module.exports = (api, options) => {
65
const cwd = api.getCwd()
76
const webpack = require('webpack')
8-
const webpackMajor = semver.major(webpack.version)
97
const vueMajor = require('../util/getVueMajor')(cwd)
108

119
api.chainWebpack(webpackConfig => {
1210
const isLegacyBundle = process.env.VUE_CLI_MODERN_MODE && !process.env.VUE_CLI_MODERN_BUILD
1311
const resolveLocal = require('../util/resolveLocal')
1412

1513
// https://github.com/webpack/webpack/issues/11467#issuecomment-691873586
16-
if (webpackMajor !== 4) {
17-
webpackConfig.module
18-
.rule('esm')
19-
.test(/\.m?jsx?$/)
20-
.resolve.set('fullySpecified', false)
21-
}
14+
webpackConfig.module
15+
.rule('esm')
16+
.test(/\.m?jsx?$/)
17+
.resolve.set('fullySpecified', false)
2218

2319
webpackConfig
2420
.mode('development')

0 commit comments

Comments
 (0)