lukeed / tsm

TypeScript Module Loader
MIT License
1.18k stars 19 forks source link

Watch mode #24

Closed artalar closed 2 years ago

artalar commented 2 years ago

Any plans for watch mode?

lukeed commented 2 years ago

No, not sure how that makes any sense for the usage. mind sharing an example? tsm is basically a node replacement or used within existing programs as a transformer

leosuncin commented 2 years ago

No, not sure how that makes any sense for the usage. mind sharing an example? tsm is basically a node replacement or used within existing programs as a transformer

As a replace of nodemon or ts-node-dev

TrySound commented 2 years ago

We implement watch mode like this. The use case is restarting server on any change. Very handy.

import { spawn } from 'child_process';
import { watch } from 'watchlist';

let childProcess = null;

const startServer = () => {
  if (childProcess) {
    childProcess.kill();
  }

  console.info('Starting/Restarting dev server');

  childProcess = spawn('node', ['--loader=tsm', 'src/docs.ts'], {
    stdio: 'inherit',
    env: process.env,
  });
};

watch(['.'], startServer, { eager: true });
pma9 commented 2 years ago

You can use nodemon with config files that use tsm. https://github.com/remy/nodemon#config-files

JanTvrdik commented 2 years ago

Or tsx watch.