forked from forabi/WebCeph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreprocessor.js
More file actions
29 lines (25 loc) · 751 Bytes
/
preprocessor.js
File metadata and controls
29 lines (25 loc) · 751 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/* eslint-disable import/no-extraneous-dependencies */
const tsc = require('typescript');
const { transform } = require('babel-core');
const fs = require('fs');
function requireJSON(path) {
return JSON.parse(String(fs.readFileSync(path)));
}
const tsConfig = requireJSON('./tsconfig.json');
const babelConfig = requireJSON('./.babelrc');
babelConfig.presets[0] = 'babel-preset-es2015';
babelConfig.plugins = ['transform-runtime'];
module.exports = {
process(src, path) {
if (path.endsWith('.ts') || path.endsWith('.tsx')) {
const tsTranspiledSrc = tsc.transpile(
src,
tsConfig.compilerOptions,
path,
[]
);
return transform(tsTranspiledSrc, babelConfig).code;
}
return src;
},
};