Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile a ts file to js in Angular and make it accessible in root when served?

I need my file firebase-messaging-sw.ts compiled to firebase-messaging-sw.js to be accessible from the root.

I already created firebase-messaging-sw.ts in the src folder. But that doesn't work. I also added the .js file in angular.json.

So what I want is to make a ts file and compile it to js. But I don't know how to do it in Angular.

angular.json

"assets": [
              "src/favicon.ico",
              "src/assets",
              "src/firebase-messaging-sw.js"
like image 994
Raymond the Developer Avatar asked Sep 09 '25 14:09

Raymond the Developer


1 Answers

You can always use

tsc myfile.ts

to compile a separate .ts file to a separate .js file, that has nothing to do with your Angular project.

Perhaps you can even run both commands at the same time in the terminal:

Terminal

tsc myfile.ts && ng build myproject

Or add it to package.json

"scripts":{
   "build" : "tsc myfile.ts && ng build myproject"
}

npm run build
like image 113
Kokodoko Avatar answered Sep 12 '25 03:09

Kokodoko