-
Notifications
You must be signed in to change notification settings - Fork 129
Recompile only changed file #228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It's not possible to compile only a subset of your files, since the compiler needs all files for type information. However, there are two ways to speed up compilation:
Does one of these options solve your issue? |
I've been trying to write a gulp task that compiles only the changed files using gulp-watch together with this module. It is almost perfect, but because I have to use I'm using tsconfig file with all typescript files listed in it.
So, if I send the However, if I send in compiler options using I think this can be fixed/improved if the following was implemented:
These two options together will allow correctly compiling single This is because usually with |
Actually, after thinking about it some more, to make it perfect, it might need to use a new kind of tsProject that keeps track of which source files depend on which. Then when one file changes, it should compile that file and also any files that directly depend on that file. (But not the whole project.) This is so you can see if the changed file affects/causes any other files in the project to error. I actually wrote my own tswatcher script that works this way. It goes through every source file to determine dependencies and compile only dependent files on change. However I can't use it anymore because I need to use babel and sourcemaps also. For now, I'm happy with the gulp task above because it is very fast. And for type checks I can look at IDE (Visual Studio Code) or when doing full build. |
@chanon It's not easy to compile a part of the project. Type checking needs type information of the whole project, thus all files need to be passed to the compiler. The compiler needs both the files that depend on the input and the files on which the input depends. Recursively this would give the whole project (provided that all files in the project are somehow connected). If you want to speed up this process you can give up type checking and use I'd advise for big projects to use isolatedModules for development, and turn the option off for release builds. |
I saw angular-cli uses https://www.npmjs.com/package/broccoli-typescript for much faster builds :) |
They aren't using that package, they built this: [https://github.com/angular/angular/blob/master/tools/broccoli/broccoli-typescript.ts]. They seem to use file name conventions to recompile a part of the files. |
Not sure if this is something someone might still be looking for (seeing as this issue is closed). If so, hit reply and I'll share my workaround. It still requires an editor like VSCode for type-checking, but works. I could get the hack here to work. |
@ngasst I'd love to know a workaround, it makes running typescript watch and ava watch impossible as all files are retested on change |
@ngasst same here, still trying to make this work. |
Is there any way to watch change and recompile only changed file?
When I do have 1000 .ts file it takes too much time to recompile them all
The text was updated successfully, but these errors were encountered: