Webpack --watch and launching nodemon?

后端 未结 8 1552
伪装坚强ぢ
伪装坚强ぢ 2021-01-30 10:51

Thanks to an excellent answer by @McMath I now have webpack compiling both my client and my server. I\'m now on to trying to make webpack --watch be useful. Ideally

8条回答
  •  故里飘歌
    2021-01-30 11:36

    1. Install the following dependencies:

    npm install npm-run-all webpack nodemon

    1. Configure your package.json file to something as seen below:

    package.json

    {
      ...
    
      "scripts": {
        "start"        : "npm-run-all --parallel watch:server watch:build",
        "watch:build"  : "webpack --watch",
        "watch:server" : "nodemon \"./dist/index.js\" --watch \"./dist\""
      },
    
      ...
    
    }
    

    After doing so, you can easily run your project by using npm start.

    Don't forget config WatchIgnorePlugin for webpack to ignore ./dist folder.

    Dependencies

    1. npm-run-all - A CLI tool to run multiple npm-scripts in parallel or sequential.
    2. webpack - webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable of transforming, bundling, or packaging just about any resource or asset.
    3. nodemon - Simple monitor script for use during development of a node.js app.

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题