8000 feat: only needs one bundle if all targets support es module by haoqunjiang · Pull Request #6419 · vuejs/vue-cli · GitHub
[go: up one dir, main page]

Skip to content

feat: only needs one bundle if all targets support es module #6419

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 8 commits into from
Apr 16, 2021
Next Next commit
refactor: rename modern to module in target calculation code
As we are getting rid of the name "modern mode"
  • Loading branch information
haoqunjiang committed Apr 14, 2021
commit 0996b206314cb5316a2c1317395f606d77cdb88e
8 changes: 4 additions & 4 deletions packages/@vue/babel-preset-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ function getIntersectionTargets (targets, constraintTargets) {
return intersection
}

function getModernTargets (targets) {
const allModernTargets = getTargets(
function getModuleTargets (targets) {
const allModuleTargets = getTargets(
{ esmodules: true },
{ ignoreBrowserslistConfig: true }
)

// use the intersection of modern mode browsers and user defined targets config
return getIntersectionTargets(targets, allModernTargets)
return getIntersectionTargets(targets, allModuleTargets)
}

function getWCTargets (targets) {
Expand Down Expand Up @@ -177,7 +177,7 @@ module.exports = (context, options = {}) => {
targets = getWCTargets(targets)
} else if (process.env.VUE_CLI_MODERN_BUILD) {
// targeting browsers that at least support <script type="module">
targets = getModernTargets(targets)
targets = getModuleTargets(targets)
}

// included-by-default polyfills. These are common polyfills that 3rd party
Expand Down
14 changes: 8 additions & 6 deletions packages/@vue/cli-service/lib/util/targets.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
const { semver } = require('@vue/cli-shared-utils')
const { default: getTargets } = require('@babel/helper-compilation-targets')

const allModernTargets = getTargets(
// See the result at <https://github.com/babel/babel/blob/v7.13.15/packages/babel-compat-data/data/native-modules.json>
const allModuleTargets = getTargets(
{ esmodules: true },
{ ignoreBrowserslistConfig: true }
)
Expand Down Expand Up @@ -32,19 +33,20 @@ function getIntersectionTargets (targets, constraintTargets) {
return intersection
}

function getModernTargets (targets) {
function getModuleTargets (targets) {
// use the intersection of modern mode browsers and user defined targets config
return getIntersectionTargets(targets, allModernTargets)
return getIntersectionTargets(targets, allModuleTargets)
}

// get browserslist targets in current working directory
const projectTargets = getTargets()
const projectModernTargets = getModernTargets(projectTargets)
const projectModuleTargets = getModuleTargets(projectTargets)

module.exports = {
getTargets,
getModernTargets,
getModuleTargets,
getIntersectionTargets,

projectTargets,
projectModernTargets
projectModuleTargets
}
6 changes: 3 additions & 3 deletions packages/@vue/cli-service/lib/webpack/ModernModePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')

const { semver } = require('@vue/cli-shared-utils')
const { projectModernTargets } = require('../util/targets')
const { projectModuleTargets } = require('../util/targets')

const minSafariVersion = projectModernTargets.safari
const minIOSVersion = projectModernTargets.ios
const minSafariVersion = projectModuleTargets.safari
const minIOSVersion = projectModuleTargets.ios
const supportsSafari10 =
(minSafariVersion && semver.lt(semver.coerce(minSafariVersion), '11.0.0')) ||
(minIOSVersion && semver.lt(semver.coerce(minIOSVersion), '11.0.0'))
Expand Down
0