Open
Description
Assuming I have application.js with
//= require dependency1.js.ts
//= require file1.js.ts
//= require file2.js.ts
And file1.js.ts is:
/// <reference path="dependency1.js.ts" />
class File1 {}
And file2.js.ts is:
/// <reference path="dependency1.js.ts" />
class File2 {}
When I do asset compilation I end up with dependency1
being included 3 times into the resulting file.
First time it's from application.js inclusion, second and third is from file1.js.ts and file2.js.ts respectively.
As far as I can tell this happens because of: https://github.com/typescript-ruby/typescript-rails#referenced-typescript-dependencies
Questions:
- Is it possible to include a dependency once? I want asset-pipeline handle this (because we have a big project where everything is setup using asset pipeline).
- If not, how can I change the inclusion/walking process? Should I use tsconfig.json for this or something else?
Thanks for your help
Metadata
Metadata
Assignees
Labels
No labels
Activity
bdrazhzhov commentedon Feb 9, 2017
Hi @Valve,
It's known issue. But right now I have no time for this gem support. I accept PR from other people only which fix some issues or add new features.
markeissler commentedon May 4, 2017
I'm having a look at this right now. The problem is actually more deeply rooted than this gem...the problem is found in the typescript-node gem because it specifies
--out
as a compiler flag. When you specify--out
a file will be generated that includes referenced dependencies. And that's how we end up with duplication.Well,
tsconfig.json
is completely ignored by this gem at the moment but even if it wasn't ignored it still wouldn't fix the problem.Valve commentedon May 4, 2017
@markeissler I looked into it myself some time ago and found what you've found too :) The ts compiler lacks this option it seems, but I need to check it for v 2.3. Anyway, I dropped the idea to use TS in my Rails project because of the bad state of TS tooling in Rails. I hope to give it another shot with Rails 5.1 and webpack (because it supports it with webpacker gem).
markeissler commentedon May 4, 2017
@Valve TS 2.3 still lacks any option to do this. The closest you can get is specifying
--noResolve
but it outputs a non-suppressible warning at the end letting you know what you already know: that dependencies are missing since you asked to skip the inclusion of dependencies. Doh!Another option would be to compile using --outDir and then select and cache files that have been already compiled but that's a silly waste of time on a bigger project. This is what happens with all of this highly opinionated software dev. :(
I'm considering just ditching the dependency on typescript-node (and, in turn, typescript-src) and just leaning on a call to
tsc
directly. Which would then allow for tsconfig.json support.markeissler commentedon May 16, 2017
@Valve I just released a new gem (typescript-monkey) that behaves in a more rails-like fashion. My gem also supports inline typescript (using <script> tags).