Skip to content

refactor: remove redundant Webpack version checks #6638

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 2 commits into from
Aug 31, 2021
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
25 changes: 6 additions & 19 deletions packages/@vue/cli-plugin-pwa/lib/HtmlPwaPlugin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { semver } = require('@vue/cli-shared-utils')

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

Expand Down Expand Up @@ -203,24 +202,12 @@ module.exports = class HtmlPwaPlugin {
size: () => outputManifest.length
}

let webpackMajor = 4
if (compiler.webpack) {
webpackMajor = semver.major(compiler.webpack.version)
}

if (webpackMajor === 4) {
compiler.hooks.emit.tapAsync(ID, (data, cb) => {
data.assets[manifestPath] = manifestAsset
cb(null, data)
})
} else {
compiler.hooks.compilation.tap(ID, compilation => {
compilation.hooks.processAssets.tap(
{ name: ID, stage: 'PROCESS_ASSETS_STAGE_ADDITIONS' },
assets => { assets[manifestPath] = manifestAsset }
)
})
}
compiler.hooks.compilation.tap(ID, compilation => {
compilation.hooks.processAssets.tap(
{ name: ID, stage: 'PROCESS_ASSETS_STAGE_ADDITIONS' },
assets => { assets[manifestPath] = manifestAsset }
)
})
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = (api, { target, entry, name, 'inline-vue': inlineVue }) => {
// Disable CSS extraction and turn on CSS shadow mode for vue-style-loader
process.env.VUE_CLI_CSS_SHADOW_MODE = true

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

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

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

return rawConfig
}
Expand Down
19 changes: 4 additions & 15 deletions packages/@vue/cli-service/lib/config/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,10 @@ module.exports = (api, options) => {
.filename(outputFilename)
.chunkFilename(outputFilename)

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

// code splitting
if (process.env.NODE_ENV !== 'test') {
Expand Down Expand Up @@ -72,13 +67,7 @@ module.exports = (api, options) => {
scriptLoading: 'defer',
templateParameters: (compilation, assets, assetTags, pluginOptions) => {
// enhance html-webpack-plugin's built in template params
let stats
return Object.assign({
// make stats lazy as it is expensive
// TODO: not sure if it's still needed as of <https://github.com/jantimon/html-webpack-plugin/issues/780#issuecomment-390651831>
get webpack () {
return stats || (stats = compilation.getStats().toJson())
},
compilation: compilation,
webpackConfig: compilation.options,
htmlWebpackPlugin: {
Expand Down
12 changes: 4 additions & 8 deletions packages/@vue/cli-service/lib/config/base.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
const path = require('path')
const { semver } = require('@vue/cli-shared-utils')

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

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

// https://github.com/webpack/webpack/issues/11467#issuecomment-691873586
if (webpackMajor !== 4) {
webpackConfig.module
.rule('esm')
.test(/\.m?jsx?$/)
.resolve.set('fullySpecified', false)
}
webpackConfig.module
.rule('esm')
.test(/\.m?jsx?$/)
.resolve.set('fullySpecified', false)

webpackConfig
.mode('development')
Expand Down