Skip to content
This repository was archived by the owner on Jul 28, 2021. It is now read-only.

Commit a6daeb1

Browse files
committed
fix(babel): switch to esm from repo and fix babel usage
1 parent 9d9ac2b commit a6daeb1

File tree

3 files changed

+527
-98
lines changed

3 files changed

+527
-98
lines changed

lib/node/extensions.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,31 @@ function overrideNode () {
88

99
let babel
1010

11+
let reactPlugin
1112
Module._extensions['.jsx'] = (module, filename) => {
1213
const content = fs.readFileSync(filename, 'utf8')
1314
if (!babel) { babel = require('babel-core') }
15+
if (!reactPlugin) {
16+
reactPlugin = require('babel-plugin-transform-react-jsx')
17+
}
1418
const { code } = babel.transform(content, {
15-
plugins: [['transform-react-jsx', {
19+
plugins: [[reactPlugin, {
1620
pragma: 'h',
1721
useBuiltIns: true
1822
}]]
1923
})
2024
module._compile(code, filename)
2125
}
2226

27+
let tsPlugin
2328
Module._extensions['.ts'] = (module, filename) => {
2429
const content = fs.readFileSync(filename, 'utf8')
25-
if (!babel) { babel = require('typescript') }
26-
const { transformed } = babel.transform(content, {
27-
plugins: ['transform-typescript']
30+
if (!babel) { babel = require('babel-core') }
31+
if (!tsPlugin) { tsPlugin = require('babel-plugin-transform-typescript') }
32+
const { code } = babel.transform(content, {
33+
plugins: [tsPlugin]
2834
})
29-
module._compile(transformed[0], filename)
35+
module._compile(code, filename)
3036
}
3137
Module._extensions['.tsx'] = Module._extensions['.ts']
3238
}

0 commit comments

Comments
 (0)