Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Can a ts_library depend on a .js file? #140

Closed
gonzojive opened this issue Jan 30, 2018 · 5 comments
Closed

Can a ts_library depend on a .js file? #140

gonzojive opened this issue Jan 30, 2018 · 5 comments

Comments

@gonzojive
Copy link

I have been using a hacky tsconfig.json to combine several .ts and .js files. I'm not sure how to achieve the same result with Bazel TypeScript rules. Is it possible?

{
  "compilerOptions": {
    "target": "es5",                          
    "module": "system",                   
    "lib": ["es6"],                           
    "declaration": false,                 
    "outFile": "./compiled_typescript.js", 
    "strict": true,  
    "downlevelIteration": true, 
    "allowJs": true   
},
  "files": [
    "system-production.src.js",
    "resize.ts",
    "tilespec.ts",
    "app.js"
  ]
}
@alexeagle
Copy link
Contributor

Currently the only way to get js files into the compilation is via the node_modules.
What are you trying to do?

@gonzojive
Copy link
Author

Ultimately, I suppose I'm trying to use tsc to compile a set of files into a single file using --outfile and --module=System. It seems this bundling is not yet supported by rules_typescript.

I thought initially I could at least declare system-production.src.js as a dep of my rule for tilespec.ts since there is a dependency on the system library.

@alexeagle
Copy link
Contributor

We do have bundling rules, but they are somewhat opinionated. The first-party support (in bazelbuild/angular repos) will choose a specific, well-paved toolchain that tries to support many use cases. I suggest you try that bundling approach before rolling your own. Did you see rollup_bundle in rules_nodejs?
Of course if we determine your use case is really special, then you're free to write your own skylark rules that bundle in whatever way you like.

@gonzojive
Copy link
Author

The rollup_bundle rule mostly works, thanks.

I ended up also adding a concat rule because of a need to export some global definitions. I'll inquire about how to pass more options to rollup_bundle on the other project because my concat rule is trying to accomplish the same thing as passing --intro or --globals to rollup. (Rollup API)

If anyone is curious about the working project, see the BUILD.bazel file for the project.

@alexeagle
Copy link
Contributor

Good to hear!

I'll certainly add more configurability for rollup and uglify, I'm just waiting to understand the use cases so we expose the minimal configuration affordances. For --globals we already snuck one of them in:
https://github.com/bazelbuild/rules_nodejs/blob/master/internal/rollup/uglify.config.json#L7
and could conceivably hard-code more of them ("global" in the real sense that every Bazel user would get these) but a map-typed attribute seems reasonable too.

--intro I am not sure, as you observe you can easily have another action prepend some text, and a packaging rule is inevitably downstream of the rollup bundle.

Seems like your OP here is resolved, please open issues on rules_nodejs to add the configuration abilities you need.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants