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

Commit

Permalink
feat(loader): add TS and jsx support
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Oct 12, 2018
1 parent 33855e7 commit d6950a1
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 7 deletions.
22 changes: 22 additions & 0 deletions lib/node/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ function overrideNode () {

const CHAR_FORWARD_SLASH = '/'.charCodeAt(0)

let jsx
Module._extensions['.jsx'] = (module, filename) => {
const content = fs.readFileSync(filename, 'utf8')
if (!jsx) { jsx = require('jsx-transform') }
const transformed = jsx.fromString(content, {factory: 'h'})
module._compile(transformed, filename)
}

let ts
Module._extensions['.ts'] = (module, filename) => {
const content = fs.readFileSync(filename, 'utf8')
if (!ts) { ts = require('typescript') }
const {outputText} = ts.transpileModule(content, {
compilerOptions: {
module: ts.ModuleKind.CommonJS
},
fileName: filename
})
module._compile(outputText, filename)
}
Module._extensions['.tsx'] = Module._extensions['.ts']

stat.cache = new Map()
function stat (filename) {
filename = path.resolve(path.toNamespacedPath(filename))
Expand Down
143 changes: 136 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"find-npm-prefix": "^1.0.2",
"get-stream": "^3.0.0",
"graceful-fs": "^4.1.11",
"jsx-transform": "^2.4.0",
"lock-verify": "^2.0.2",
"npm-lifecycle": "^2.0.3",
"npm-logical-tree": "^1.2.1",
Expand All @@ -61,6 +62,7 @@
"stringify-package": "^1.0.0",
"tacks": "^1.2.7",
"tar": "^4.4.4",
"typescript": "^3.1.1",
"yargs": "^12.0.1"
},
"config": {
Expand Down

0 comments on commit d6950a1

Please sign in to comment.