C
Join ServerC#
help
โ Upgrading Javascript to Typescript in MVC project
LLary12/7/2022
I globally installed npm and typescript. Then created a tsconfig.json in my project. But I have no idea what to do after that.
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)
Installing typescript in App.Web was a torture. I gave up and installed it globally.
"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
Installing typescript in App.Web was a torture. I gave up and installed it globally.
AAntonC12/7/2022
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
LLary12/7/2022
Umm... english?
AAntonC12/7/2022
I have a local development server for serving the static files (vite)
LLary12/7/2022
I see. I want the other ways then
AAntonC12/7/2022
the aspnet core server uses a reverse proxy to reroute the requests it doesn't know about to it
AAntonC12/7/2022
aka static files
AAntonC12/7/2022
in development
LLary12/7/2022
ts files are compiled and transformed into js files to be used by the app later right?
AAntonC12/7/2022
transpiled, minimized and bundled
AAntonC12/7/2022
I copy them in my publish script (using Nuke)
LLary12/7/2022
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?
LLary12/7/2022
I see. But I don't want to make it too complicated
AAntonC12/7/2022
then you'll have to do builds manually
LLary12/7/2022
alright.
AAntonC12/7/2022
setting up msbuild to do this is insanity
AAntonC12/7/2022
copying files in a batch or shell script is a pain and is not portable
LLary12/7/2022
I mean, I saw something like "tsc: build" on internet. Had no luck finding it though
LLary12/7/2022
in ctrl shift p
AAntonC12/7/2022
Nuke is pretty easy to use, take a look at it eventually
LLary12/7/2022
okay i will
LLary12/7/2022
I just wanted to learn the normal way of doing it first
LLary12/7/2022
most primordinal one
LLary12/7/2022
so i can grasp it better
AAntonC12/7/2022
AAntonC12/7/2022
yeah there may be tools for it that do typescript in another way
LLary12/7/2022
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
LLary12/7/2022
error TS6053: File 'index.ts' not found.
The file is in the program because:
Root file specified for compilation
AAntonC12/7/2022
Idk, haven't used raw typescript, only used vite
LLary12/7/2022
I see, no problem. I will wait for an another kind soul I guess ๐ Thanks for the try!
LLary12/7/2022
npx tsc TypeScript/index.ts
I see, it still needs the location. It transformed it but outDir is not working.
LLary12/7/2022
I want it to send it to wwwroot/js
AAntonC12/7/2022
there might be some option for it, or a setting in a config file
LLary12/7/2022
found it
LLary12/7/2022
no, you CAN'T DO THIS TO ME!!! ๐ ๐
LLary12/7/2022
it's just tsc
LLary12/7/2022
"tsc"
LLary12/7/2022
done
LLary12/7/2022
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.
LLary12/7/2022
tsconfig.json has "include" which tries to find .ts files to compile. Then puts them in "outDir" location. smh!
AAccord12/7/2022
Closed!