Skip to content

Commit 0b87fed

Browse files
committed
fix: extend babelrc
1 parent 6a55fcf commit 0b87fed

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/mp-compiler/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
const compiler = require('mpvue-template-compiler')
33
const htmlBeautify = require('js-beautify').html
44

5+
const path = require('path')
56
const babel = require('babel-core')
67
const { parseConfig, parseComponentsDeps } = require('./parse')
78
const { genScript, genStyle, genPageWxml } = require('./templates')
@@ -91,7 +92,8 @@ function compileWxml (compiled, html) {
9192
// 针对 .vue 单文件的脚本逻辑的处理
9293
// 处理出当前单文件组件的子组件依赖
9394
function compileMPScript (script, optioins, moduleId) {
94-
const { metadata } = babel.transform(script.content, { plugins: [parseComponentsDeps] })
95+
const babelrc = optioins.globalBabelrc ? optioins.globalBabelrc : path.resolve('./.babelrc')
96+
const { metadata } = babel.transform(script.content, { extends: babelrc, plugins: [parseComponentsDeps] })
9597

9698
// metadata: importsMap, components
9799
const { importsMap, components: originComponents } = metadata
@@ -135,7 +137,9 @@ const startPageReg = /^\^/
135137

136138
function compileMP (content, optioins) {
137139
const { resourcePath, emitError, emitFile, emitWarning, resolve, context } = this
138-
const { metadata } = babel.transform(content, { plugins: [parseConfig] })
140+
141+
const babelrc = optioins.globalBabelrc ? optioins.globalBabelrc : path.resolve('./.babelrc')
142+
const { metadata } = babel.transform(content, { extends: babelrc, plugins: [parseConfig] })
139143

140144
// metadata: config
141145
const { config, rootComponent } = metadata

0 commit comments

Comments
 (0)