Skip to content

Commit

Permalink
refactor: remove usage of deprecated babel functions, preparing for b…
Browse files Browse the repository at this point in the history
…abel 8 (vuejs#5133)

* refactor: use babel.loadPartialConfigSync (added in babel 7.8)

As planned in babel/babel#10746,
in babel 8 the old `loadPartialConfig` can't be used synchronously.

* refactor: remove dependence on internal babel files, preparing for babel 8

See
babel/babel#10746
babel/babel#10899
  • Loading branch information
sodatea authored and mactanxin committed Feb 11, 2020
1 parent 16f6049 commit a8726f2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
19 changes: 9 additions & 10 deletions packages/@vue/babel-preset-app/index.js
Expand Up @@ -14,17 +14,16 @@ const defaultPolyfills = [
]

function getPolyfills (targets, includes, { ignoreBrowserslistConfig, configPath }) {
const { isPluginRequired } = require('@babel/preset-env')
const builtInsList = require('core-js-compat/data')
const getTargets = require('@babel/preset-env/lib/targets-parser').default
const builtInTargets = getTargets(targets, {
ignoreBrowserslistConfig,
configPath
})
const getTargets = require('@babel/helper-compilation-targets').default
const builtInTargets = getTargets(targets, { ignoreBrowserslistConfig, configPath })

// if no targets specified, include all default polyfills
if (!targets && !Object.keys(builtInTargets).length) {
return includes
}

return includes.filter(item => {
return isPluginRequired(builtInTargets, builtInsList[item])
})
const { list } = require('core-js-compat')({ targets: builtInTargets })
return includes.filter(item => list.includes(item))
}

module.exports = (context, options = {}) => {
Expand Down
1 change: 1 addition & 0 deletions packages/@vue/babel-preset-app/package.json
Expand Up @@ -23,6 +23,7 @@
"homepage": "https://github.com/vuejs/vue-cli/tree/dev/packages/@vue/babel-preset-app#readme",
"dependencies": {
"@babel/core": "^7.8.4",
"@babel/helper-compilation-targets": "^7.8.4",
"@babel/helper-module-imports": "^7.8.3",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-proposal-decorators": "^7.8.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-plugin-babel/index.js
Expand Up @@ -26,7 +26,7 @@ module.exports = (api, options) => {
// there will be a VUE_CLI_TRANSPILE_BABEL_RUNTIME env var set.
// the `filename` field is required
// in case there're filename-related options like `ignore` in the user config
babel.loadPartialConfig({ filename: api.resolve('src/main.js') })
babel.loadPartialConfigSync({ filename: api.resolve('src/main.js') })

api.chainWebpack(webpackConfig => {
webpackConfig.resolveLoader.modules.prepend(path.join(__dirname, 'node_modules'))
Expand Down

0 comments on commit a8726f2

Please sign in to comment.