How do I get tslint to watch for changes in a specific folder?

前端 未结 2 1198
夕颜
夕颜 2021-01-12 14:50

I am using webpack 2, and it will tell me if there are compile issues with my typescript code. However, I have not figured out a way to run tslint through it and have it run

相关标签:
2条回答
  • 2021-01-12 15:19

    If you are using TypeScript, then you can probably use tsc -w to watch the changes.

     "scripts": {
        "start": "tsc -w",
      }
    
    0 讨论(0)
  • 2021-01-12 15:29

    As far as a script you can run from the command line is concerned, you can try using npm-watch: https://www.npmjs.com/package/npm-watch.

    I've used it to successfully do what you're talking about. Here's what I did:

    Installed npm-watch to my project:

    $ npm install npm-watch --save-dev
    

    Added the following to my package.json file:

    "watch": {
        "lint": "src/main.ts"
    },
    "scripts": {
        "lint": "tslint src/**/*.ts -t verbose",
        "watch": "npm-watch"
    },
    

    I figure npm-watch is a good tool for giving watch functionality to tools that don't have it, like tslint.

    Update:

    Also, if you don't want to add a "watch" section to your package.json file, I've actually just discovered a new tool I like even better called chokidar. It allows you to specify the file selectors and command you want to run all on the same line.

    Here's my updated package.json:

    "scripts": {
        "lint:watch": "chokidar webpack.config.* src/**/*.ts buildScripts/**/*.ts -c \"npm run lint\" --initial --verbose"
    },
    

    You basically give it one or more file selectors, and then use the '-c' parameter to specify the command you want run when any of those files are changed.

    So now you can just run the command:

    $ npm run lint:watch
    

    I like to run it with the --initial flag set, so it doesn't wait for any files to change before executing the command.

    0 讨论(0)
提交回复
热议问题