Active9 months ago
Node.jsĀ® is a JavaScript runtime built on Chrome's V8 JavaScript engine. Latest LTS Version: 10.16.3 (includes npm 6.9.0) Download the Node.js source code or a pre-built installer for your platform, and start developing today. I have an HTML file with embedded Javascript, and I want to convert it to a stand-alone exe. Is that possible? How can I do it? Any html2exe tool out there? If you must ask why, it's a very.
Well I just wanted to know is there any command which will directly compile the typescript code and get the output. Right now, what i am doing is,every time when i make changes in the file i have to re run the command inorder to compile it
This starts the browser and then i have to stop the execution using ctrl + c and then i have to run the file using the npm command
to see the output.
So what i want to know is, is there any npm command which will compile the .ts file and see the changes which i have made in the file while i run the file using the
command
Liam17.3k1616 gold badges8080 silver badges135135 bronze badges
Lijin DurairajLijin Durairaj1,23566 gold badges1717 silver badges4343 bronze badges
3 Answers
You can launch the
tsc
command (typescript compiler) with --watch
argument.Here is an idea :
- Configure typescript using
tsconfig.json
file - Run
tsc --watch
, so every time you change a.ts
file,tsc
will compile it and produce the output (let say you configured typescript to put the output in./dist
folder) - Use
nodemon
to watch if files in./dist
have changed and if needed to relaunch the server.
Here are some scripts (to put in
package.json
) that can help you to do it (you will need to install the following modules npm install --save typescript nodemon npm-run-all rimraf
)Then you just need to run
ThomasThiebaudThomasThiebaudnpm start
in a terminal6,21233 gold badges2929 silver badges5151 bronze badges
This is based on solution proposed by @ThomasThiebaud. I had to modify it a little to make sure the files are built in
dist/
before nodemon tries to start the server.You still need to run
demisxdemisxnpm start
to start the whole thing.2,47722 gold badges2727 silver badges2929 bronze badges
Here is my approach, let say that you keep all your
typescript
files in src
folder and want outputted javascript
files be generated in the ./dist
folder.and typescript configuration file
tsconfig.json
Okay, what is going on here
First of all we should create
tsconfig.json
and tell typescript to put compiled files into the ./dist
folder and at the same time we should exclude node_module
folder or whatever we want and include everything from ['./src/**/*']
directory.After that in
packages.json
file we should specify path to our compiled index.js
file'main': './dist/index'
and finally we tell
tsc
to --watch
any typescript
changes, and nodemon
to watch inside ./dist
directory and if something changes nodemon
will restart the server.To run script type
npm run dev
Gh111Gh111