|
1 | 1 | const babel = require('babel-core')
|
2 | 2 | const findBabelConfig = require('find-babel-config')
|
3 | 3 | const logger = require('../logger')
|
| 4 | +const cache = require('../cache') |
4 | 5 |
|
5 | 6 | var defaultBabelOptions = {
|
6 | 7 | presets: ['es2015'],
|
7 | 8 | plugins: ['transform-runtime']
|
8 | 9 | }
|
9 | 10 |
|
10 |
| -module.exports = function compileBabel (scriptContent, inputSourceMap) { |
11 |
| - const { file, config } = findBabelConfig.sync(process.cwd(), 0) |
12 |
| - |
13 |
| - if (!file) { |
14 |
| - logger.info('no .babelrc found, defaulting to default babel options') |
| 11 | +function getBabelConfig () { |
| 12 | + const cachedConfig = cache.get('babel-config') |
| 13 | + if (cachedConfig) { |
| 14 | + return cachedConfig |
| 15 | + } else { |
| 16 | + const { file, config } = findBabelConfig.sync(process.cwd(), 0) |
| 17 | + if (!file) { |
| 18 | + logger.info('no .babelrc found, defaulting to default babel options') |
| 19 | + } |
| 20 | + const babelConfig = file ? config : defaultBabelOptions |
| 21 | + cache.set('babel-config', babelConfig) |
| 22 | + return babelConfig |
15 | 23 | }
|
| 24 | +} |
16 | 25 |
|
| 26 | +module.exports = function compileBabel (scriptContent, inputSourceMap) { |
17 | 27 | const sourceMapOptions = {
|
18 | 28 | sourceMaps: true,
|
19 |
| - inputSourceMap: inputSourceMap || null |
| 29 | + inputSourceMap: inputSourceMap |
20 | 30 | }
|
21 | 31 |
|
22 |
| - const baseBabelOptions = file ? config : defaultBabelOptions |
23 |
| - const babelOptions = Object.assign(sourceMapOptions, baseBabelOptions) |
| 32 | + const babelConfig = getBabelConfig() |
| 33 | + |
| 34 | + const babelOptions = Object.assign(sourceMapOptions, babelConfig) |
24 | 35 |
|
25 | 36 | const res = babel.transform(scriptContent, babelOptions)
|
26 | 37 |
|
|
0 commit comments