C
C#2y ago
İrşat

✅ Upgrading Javascript to Typescript in MVC project

I globally installed npm and typescript. Then created a tsconfig.json in my project. But I have no idea what to do after that.
"include": ["TypeScript"],
"compilerOptions": {
"outDir": "./wwwroot/js",
"include": ["TypeScript"],
"compilerOptions": {
"outDir": "./wwwroot/js",
I am trying to put my .ts files in TypeScript folder directly under the App.Web. Both TypeScript folder and tsconfig.json are right under App.Web. (I have 2 apps in one project. App.Web and App.Api)
App.Web
MVC structure
TypeScript
firsttry.ts
tsconfig.json
App.Api
App.Web
MVC structure
TypeScript
firsttry.ts
tsconfig.json
App.Api
Installing typescript in App.Web was a torture. I gave up and installed it globally.
22 Replies
Anton
Anton2y ago
Don't know what's the best way is, I just used vite, set up a reverse proxy on the aspnet core side, and made some tag helpers that remap the links to ts files to js bundles in production
İrşat
İrşatOP2y ago
Umm... english?
Anton
Anton2y ago
I have a local development server for serving the static files (vite)
İrşat
İrşatOP2y ago
I see. I want the other ways then
Anton
Anton2y ago
the aspnet core server uses a reverse proxy to reroute the requests it doesn't know about to it aka static files in development
İrşat
İrşatOP2y ago
ts files are compiled and transformed into js files to be used by the app later right?
Anton
Anton2y ago
transpiled, minimized and bundled I copy them in my publish script (using Nuke)
İrşat
İrşatOP2y ago
In this case it should have a small code to transform all of them in one go. For this I need a root folder for ts files and output folder for transformed js files right? I see. But I don't want to make it too complicated
Anton
Anton2y ago
then you'll have to do builds manually
İrşat
İrşatOP2y ago
alright.
Anton
Anton2y ago
setting up msbuild to do this is insanity copying files in a batch or shell script is a pain and is not portable
İrşat
İrşatOP2y ago
I mean, I saw something like "tsc: build" on internet. Had no luck finding it though in ctrl shift p
Anton
Anton2y ago
Nuke is pretty easy to use, take a look at it eventually
İrşat
İrşatOP2y ago
okay i will I just wanted to learn the normal way of doing it first most primordinal one so i can grasp it better
Anton
Anton2y ago
GitHub
49/Build.cs at main · AntonC9018/49
Contribute to AntonC9018/49 development by creating an account on GitHub.
Anton
Anton2y ago
yeah there may be tools for it that do typescript in another way
İrşat
İrşatOP2y ago
I guess I forgot to mention it. I am doing "npx tsc firsttry.ts". If they are all in root folder, it works. But I have problem with giving locations. It says it can't find it
error TS6053: File 'index.ts' not found. The file is in the program because: Root file specified for compilation
Anton
Anton2y ago
Idk, haven't used raw typescript, only used vite
İrşat
İrşatOP2y ago
I see, no problem. I will wait for an another kind soul I guess 😄 Thanks for the try! npx tsc TypeScript/index.ts I see, it still needs the location. It transformed it but outDir is not working. I want it to send it to wwwroot/js
Anton
Anton2y ago
there might be some option for it, or a setting in a config file
İrşat
İrşatOP2y ago
found it no, you CAN'T DO THIS TO ME!!! 😄 😄 it's just tsc "tsc" done what happens is basically it reads tsconfig.json. When I write "tsc TypeScript/index.ts", it doesn't read it or something and hence puts the js file right next to it. tsconfig.json has "include" which tries to find .ts files to compile. Then puts them in "outDir" location. smh!
Accord
Accord2y ago
Closed!
Want results from more Discord servers?
Add your server