-
-
Notifications
You must be signed in to change notification settings - Fork 434
Description
ts-loader compiles a lot more files than it should. ts-loader should only compile files known to webpack (e.g webpack.config.js entry + its children) (and/or files specified in tsconfig.json (*))
Setup:
- webpack.config.js with an entry ./index.ts + ts-loader
- a file fail.ts:
// Fail to compile with TypeScript with "'const' declarations must be initialized"
// + is not imported by index.ts
const fail;
Results:
- Case 1 no tsconfig.json
ERROR in error TS18002: The 'files' list in config file 'tsconfig.json' is empty.
ERROR in ./index.ts
Module build failed: error while parsing tsconfig.json
=> KO, ts-loader should work without a file tsconfig.json (or at least the error message is incorrect and should be "error: no tsconfig.json")
- Case 2 empty tsconfig.json without files and include
ERROR in /Users/tanguy/flex-wrap-layout/src/fail.ts
(1,7): error TS1155: 'const' declarations must be initialized.
=> KO, this is the main case, fail.ts is not specified anywhere (tsconfig.json and webpack.config.js) so ts-loader should not compile it.
- Case 3 tsconfig.json with files (*)
- Case 3.1 files with index.ts (
"files": ["index.ts"]
): no error => this is OK - Case 3.2 files with index.ts and fail.ts (
"files": ["index.ts", "fail.ts"]
): fail.ts error => this is OK
- Case 3.1 files with index.ts (
Comparison with rollup-plugin-typescript2:
- Case 1:
[!] Error: couldn't find 'tsconfig.json'
- Case 2: does not compile fail.ts => OK
- Case 3.1: does not compile fail.ts => OK
- Case 3.2: does not compile fail.ts
- Case 3.2bis
"include": ["*.ts"]
: does not compile fail.ts
(*) I even believe that ts-loader should totally ignore tsconfig.json files (but use compilerOptions of course) and only rely on webpack.config.js entry (and its imported children). This is what rollup-plugin-typescript2 does.