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

Commit

Permalink
fix(babel): switch to esm from repo and fix babel usage
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Jan 2, 2019
1 parent 9d9ac2b commit a6daeb1
Show file tree
Hide file tree
Showing 3 changed files with 527 additions and 98 deletions.
16 changes: 11 additions & 5 deletions lib/node/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,31 @@ function overrideNode () {

let babel

let reactPlugin
Module._extensions['.jsx'] = (module, filename) => {
const content = fs.readFileSync(filename, 'utf8')
if (!babel) { babel = require('babel-core') }
if (!reactPlugin) {
reactPlugin = require('babel-plugin-transform-react-jsx')
}
const { code } = babel.transform(content, {
plugins: [['transform-react-jsx', {
plugins: [[reactPlugin, {
pragma: 'h',
useBuiltIns: true
}]]
})
module._compile(code, filename)
}

let tsPlugin
Module._extensions['.ts'] = (module, filename) => {
const content = fs.readFileSync(filename, 'utf8')
if (!babel) { babel = require('typescript') }
const { transformed } = babel.transform(content, {
plugins: ['transform-typescript']
if (!babel) { babel = require('babel-core') }
if (!tsPlugin) { tsPlugin = require('babel-plugin-transform-typescript') }
const { code } = babel.transform(content, {
plugins: [tsPlugin]
})
module._compile(transformed[0], filename)
module._compile(code, filename)
}
Module._extensions['.tsx'] = Module._extensions['.ts']
}
Loading

0 comments on commit a6daeb1

Please sign in to comment.