Saturday 18 March 2017

Live compiling Typescript to es5 and immediate run

So recently I've decided to try to rewrite one of my "little" projects from es5 to Typescript. It's a Node.js Rest api based on express.js.

Is there a way how to recompile a TS project into a single file on change and primarily also run the app?

When using react/es6 I'm using webpack dev server, which can recompile on change pretty quickly. When using es5 in node.js I'm using nodemon, which immediately re-runs the code on change. But how to properly combine these two functionalities? Should I use webpack to compile TS code? But is webpack capable of also running the code?

I've seen an example of using the ts compiler with nodemon, but using this way it's not possible to create one single output bundle.

src
  |- entryPoint.ts
  |- routes
  |    |- foo.ts
  |    |- bar.ts
  |    |- ...
  |- schemas
  |    |- foo.ts
  |    |- bar.ts
  |    |- ...
  |- ...
dist
  |- singleOutputBundle.js
tsconfig.json
nodemon.json
webpack.config.js
package.json



via Patrik Šimunič

No comments:

Post a Comment