Skip to content
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

Allow .ts files in angular.json scripts to be transpiled to target ES version #17125

Closed
2 tasks done
denkan opened this issue Feb 29, 2020 · 6 comments
Closed
2 tasks done

Comments

@denkan
Copy link

denkan commented Feb 29, 2020

🚀 Feature request

Command

  • build
  • serve

Description

There are scenarios where we need to include a specific file to the bundle. Today, we can do this by using the scripts option in angular.json. But this only works for .js files.

It would be great to be able to specify .ts files too, which then get transpiled into target ES version.
This would e.g. allow us to include separate files which reads from environments.ts vars correctly.

My specific scenario:
I'm implementing Firebase Messaging, which require firebase-messaging-sw.js in the root and contains config vars for messagingSenderId (which I have stored in environment.ts).

Describe the solution you'd like

When specifying an input with .ts extension, the builder transpiles it into .js.

"scripts": [
  { "input": "src/firebase-messaging-sw.ts", "inject": false, "bundleName": "firebase-messaging-sw" }
]

Describe alternatives you've considered

This solution suggests to transpile the .ts file before the Angular build (tsc my-file.ts && ng build).
But then we won't access the correct environment.ts, as it gets determent in the Angular build...

@clydin
Copy link
Member

clydin commented Feb 29, 2020

The scripts option is intended to be functionally equivalent to adding a script element to the index HTML file for an application. It is primarily a convenience option to remove the need for developers to manage multiple index HTML files within a single application solely to support multiple configurations with differing script element requirements.

To allow for the behavior as described in the above issue, the scripts option would need to be changed into what would essentially be a miniature application builder. Not only would TypeScript processing be necessary but also bundling (with the potential for ES target downleveling and other post-processing steps). Additional script options for specifying a tsconfig and bundling options would be needed on a per script level as well to support the requirements of the script. This unfortunately would be a large increase in complexity and is currently out of scope for this option. If generating service worker code becomes common, then a standalone builder and a separate project within the Angular workspace may be the most beneficial long-term solution for this problem space.

@flash-me
Copy link

flash-me commented Mar 2, 2020

Hi @denkan

why not manually transpiling your TypeScript files with tsc and appropriate tsconfig.json?

  • Create a dedicate tsconfig.scripts.json
  • Put your required files into to files array in the config
  • tsc -b tsconfig.scripts.json

cheers
flash ⚡

@denkan
Copy link
Author

denkan commented Mar 7, 2020

@clydin
Thanks for clarification. Sad to hear it would be such a big effort to achieve.

@flash-me
Thanks for the tip. As stated in the end of my post, I've considered this option but was hoping I wouldn't need to replicate the logic for picking correct environment.ts for just one simple file, but instead getting it for free from the Angular team ;)

@flash-me
Copy link

flash-me commented Mar 7, 2020

Oh didn't see that. Oops 😁.

@alan-agius4
Copy link
Collaborator

Closing as per above comment by @clydin.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants