refactor: remove usage of deprecated babel functions, preparing for babel 8 (#5133)

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

As planned in https://github.com/babel/babel/issues/10746,
in babel 8 the old `loadPartialConfig` can't be used synchronously.

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

See
https://github.com/babel/babel/issues/10746
https://github.com/babel/babel/pull/10899
This commit is contained in:
Haoqun Jiang
2020-02-03 19:52:43 +08:00
committed by GitHub
parent da43343329
commit c8cecffedb
3 changed files with 11 additions and 11 deletions

View File

@@ -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 })
return includes.filter(item => {
return isPluginRequired(builtInTargets, builtInsList[item])
})
// if no targets specified, include all default polyfills
if (!targets && !Object.keys(builtInTargets).length) {
return includes
}
const { list } = require('core-js-compat')({ targets: builtInTargets })
return includes.filter(item => list.includes(item))
}
module.exports = (context, options = {}) => {

View File

@@ -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",

View File

@@ -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'))