Webpack --watch and launching nodemon?

后端 未结 8 1615
伪装坚强ぢ
伪装坚强ぢ 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:23

    Faced the same problem and found the next solution - "webpack-shell-plugin". It

    allows you to run any shell commands before or after webpack builds

    So, thats my scripts in package.json:

    "scripts": {
          "clean": "rimraf build",
          "prestart": "npm run clean",
          "start": "webpack --config webpack.client.config.js",
          "poststart": "webpack --watch --config webpack.server.config.js",
    }
    

    If I run 'start' script it launches next script sequence: clean -> start -> poststart. And there is part of 'webpack.server.config.js':

    var WebpackShellPlugin = require('webpack-shell-plugin');
    
    ...
    if (process.env.NODE_ENV !== 'production') {
        config.plugins.push(new WebpackShellPlugin({onBuildEnd: ['nodemon build/server.js --watch build']}));
    }
    ...
    

    "onBuildEnd" event fires only once after first build, rebuilds are not trigger "onBuildEnd", so nodemon works as intended

提交回复
热议问题