Skip to content

Commit 85f2eda

Browse files
authored
fix: should support pkg.egg.typescript = true config (#255)
1 parent 9bd5c28 commit 85f2eda

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lib/egg.js

-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ class EggCore extends KoaApplication {
3131
*/
3232
constructor(options = {}) {
3333
options.baseDir = options.baseDir || process.cwd();
34-
// auto require('tsconfig-paths/register') on typescript app
35-
if (process.env.EGG_TYPESCRIPT === 'true') {
36-
require('tsconfig-paths').register({ cwd: options.baseDir });
37-
}
3834
options.type = options.type || 'application';
3935

4036
assert(typeof options.baseDir === 'string', 'options.baseDir required, and must be a string');

lib/loader/egg_loader.js

+6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ class EggLoader {
4343
*/
4444
this.pkg = utility.readJSONSync(path.join(this.options.baseDir, 'package.json'));
4545

46+
// auto require('tsconfig-paths/register') on typescript app
47+
// support env.EGG_TYPESCRIPT = true or { "egg": { "typescript": true } } on package.json
48+
if (process.env.EGG_TYPESCRIPT === 'true' || (this.pkg.egg && this.pkg.egg.typescript)) {
49+
require('tsconfig-paths').register({ cwd: this.options.baseDir });
50+
}
51+
4652
/**
4753
* All framework directories.
4854
*

0 commit comments

Comments
 (0)