mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-06-18 20:16:44 +08:00
Merge pull request #34 from luhmann/add-tsconfig-support
Use "compilerOptions" from projects "tsconfig.json" for jest
This commit is contained in:
@@ -1,21 +1,33 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
const fs = require('fs');
|
||||
const tsc = require('typescript');
|
||||
const tsconfigPath = require('app-root-path').resolve('/tsconfig.json');
|
||||
|
||||
let compilerConfig = {
|
||||
module: tsc.ModuleKind.CommonJS,
|
||||
jsx: tsc.JsxEmit.React,
|
||||
}
|
||||
|
||||
if (fs.existsSync(tsconfigPath)) {
|
||||
try {
|
||||
const tsconfig = require(tsconfigPath);
|
||||
|
||||
if (tsconfig && tsconfig.compilerOptions) {
|
||||
compilerConfig = tsconfig.compilerOptions;
|
||||
}
|
||||
} catch (e) { /* Do nothing - default is set */ }
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
process(src, path) {
|
||||
if (path.endsWith('.ts') || path.endsWith('.tsx')) {
|
||||
return tsc.transpile(
|
||||
src,
|
||||
{
|
||||
module: tsc.ModuleKind.CommonJS,
|
||||
jsx: tsc.JsxEmit.React,
|
||||
},
|
||||
path,
|
||||
[]
|
||||
compilerConfig,
|
||||
path, []
|
||||
);
|
||||
}
|
||||
return src;
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
"react-scripts-ts": "./bin/react-scripts-ts.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"app-root-path": "^2.0.1",
|
||||
"autoprefixer": "6.7.2",
|
||||
"case-sensitive-paths-webpack-plugin": "1.1.4",
|
||||
"chalk": "1.1.3",
|
||||
|
||||
Reference in New Issue
Block a user