Skip to content
This repository was archived by the owner on May 8, 2025. It is now read-only.

Commit 820c88c

Browse files
johnleidermaurop123
authored andcommitted
fix(babel/polyfill): update logic
vue-cli@3.0.0-beta11 changed from .babelrc to babel.config.js fixes #12
1 parent b65c03e commit 820c88c

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

generator/helpers.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ module.exports = function (api) {
55
updateBabelConfig (callback) {
66
let config, configPath
77

8-
const rcPath = api.resolve('./.babelrc')
8+
const rcPath = api.resolve('./babel.config.js')
99
const pkgPath = api.resolve('./package.json')
1010
if (fs.existsSync(rcPath)) {
1111
configPath = rcPath
12-
config = JSON.parse(fs.readFileSync(rcPath, { encoding: 'utf8' }))
13-
config = callback(config)
12+
config = callback(require(rcPath))
1413
} else if (fs.existsSync(pkgPath)) {
1514
configPath = pkgPath
1615
config = JSON.parse(fs.readFileSync(pkgPath, { encoding: 'utf8' }))
@@ -23,9 +22,11 @@ module.exports = function (api) {
2322
}
2423

2524
if (configPath) {
25+
const moduleExports = configPath !== pkgPath ? 'module.exports = ' : ''
26+
2627
fs.writeFileSync(
2728
configPath,
28-
JSON.stringify(config, null, 2),
29+
`${moduleExports}${JSON.stringify(config, null, 2)}`,
2930
{ encoding: 'utf8' }
3031
)
3132
} else {

generator/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ module.exports = (api, opts, rootOpts) => {
5656
// Add polyfill
5757
if (opts.usePolyfill) {
5858
helpers.updateBabelConfig(cfg => {
59-
if (!cfg.presets) return
59+
if (!cfg.presets) return cfg
6060

6161
const vuePresetIndex = cfg.presets.findIndex(p => Array.isArray(p) ? p[0] === '@vue/app' : p === '@vue/app')
6262
const isArray = Array.isArray(cfg.presets[vuePresetIndex])
6363

64-
if (vuePresetIndex < 0) return
64+
if (vuePresetIndex < 0) return cfg
6565

6666
if (isArray) {
6767
cfg.presets[vuePresetIndex][1]['useBuiltIns'] = 'entry'

0 commit comments

Comments
 (0)