grunt-ts
grunt-ts copied to clipboard
Fast compilation with third party amd dependencies
Hi!
I am trying to use fast compile to compile a project with third party amd dependencies. I am using the following file layout:
project
|-lib
| |-jquery.d.ts
|-src
| |-a.ts
| |-b.ts
My configuration:
ts: {
options: {
module: 'amd',
target: 'es5',
fast: 'always'
},
all: {
src: ['src/**/*.ts', 'lib/**/*.d.ts'],
outDit: 'build'
}
}
src/a.ts:
import $ = require('jquery');
import b = require('./b.ts');
On the first time the compilation works just fine: it can trace jquery to lib/jquery.d.ts because it is defined as source. But on the second time, when I have just edited src/a.ts, the compiler can't find jquery and crashes. I can't just include ../lib/jquery because the file defines module named jquery which is not the same.
I suggest the compiler should include all .d.ts file in the compilation whether the file has changed or not. Or the task should include an option for telling the locations of irregular dependencies.
Henrik Lievonen
I suggest the compiler should include all .d.ts file in the compilation whether the file has changed or not. Or the task should include an option for telling the locations of irregular dependencies
:+1:
For now you need to manually <reference them. You can use transforms to help you : https://github.com/TypeStrong/grunt-ts#transforms. Just put all the definitions in a vendor.d.ts and reference that .d.ts. This is what I used to do.
Note: shameless plug : but meant in sincerity : https://github.com/TypeStrong/atom-typescript/ does a better job of fast compiling thanks to a) being in memory for the entire duration. and b) compilation context being driven by tsconfig : https://github.com/TypeStrong/atom-typescript/blob/master/docs/tsconfig.md
After v5 comes out, I want to revisit the fast functionality and see what can be done to improve it - especially considering the new --isolatedModules switch. Marking this as an enhancement for now.
I encountered the same problem on a small project of mine. It took some time until I found the problem. Maybe a note about the limitation in the readme would help.
I noticed that TypeScript 3.4 introduced the --incremental flag. Maybe this could deprecate the fast option? I haven't made any reasonable tests so far.
@JojOatXGME yes --incremental and build and friends are the way forward. I am not using this anymore and clearly have let this project drop from my priorities over the years. I think a new streamlined project that just uses the tsconfig project format is the right way forward - that way only minimal changes will ever be needed as TypeScript revs.