skip to Main Content

I’m using vite + typescript + vue3, and there is a command build like below.

I want to trigger the build command once there is a file changed, how can I achieve it besides manually installing the nodemon.

BTW, both vue-tsc and vite build support –watch individually.

"scripts": {
    "dev": "vite",
    "build": "vue-tsc && vite build",
    "preview": "vite preview"
},

2

Answers


  1. To trigger the build command in your Vite + TypeScript + Vue 3 project whenever a file changes, you can use chokidar-cli to watch your files and run the build script automatically. This way, you avoid manually installing and configuring nodemon.

        {
      "scripts": {
        "dev": "vite",
        "build": "vue-tsc && vite build",
        "preview": "vite preview",
        "watch-build": "chokidar 'src/**/*' -c 'npm run build'"
      }
    }
    

    Now just
    npm run watch-build

    You can also use fs.watch or debounce

    Login or Signup to reply.
  2. For non windows:

    You can use &:

    vue-tsc & vite build
    

    This will make first command run in background, and then run the second.

    I have tested in my local setup. While it does not open two terminals, it is easy to distinguish between the two processes as there is numbering in front of the output.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search