【问题标题】:nodemon is not watching directory in webpack-typescript-node.js?nodemon 没有在 webpack-typescript-node.js 中监视目录?
【发布时间】:2021-04-19 23:48:16
【问题描述】:

这些是 typescript-webpack-node.js 项目的 package.json 中的脚本:

"scripts": {
    "build": "webpack",
    "dev:start": "nodemon --watch src  --exec \"node -r dotenv/config --trace-deprecation  dist/bundle.js \" ",
    "dev": "npm-run-all build dev:start",
    "start": "node  dist/bundle.js",
    "tsc:build": "tsc -w",
    "tsc:start": "nodemon --watch src  --exec \"node -r dotenv/config   build/index.js \""
  },

如果我添加:

    watch: true,

到 webpack.config.json 然后服务器没有启动。我在客户端收到此错误:

【问题讨论】:

    标签: node.js typescript webpack nodemon


    【解决方案1】:
    "scripts": {
          "clean": "rimraf build",
          "prestart": "npm run clean",
          "start": "webpack --config webpack.client.config.js",
          "poststart": "webpack --watch --config webpack.server.config.js",
    }
    

    如果我运行“启动”脚本,它会启动下一个脚本序列:clean -> start -> poststart。还有'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”事件仅在第一次构建后触发一次,重建不会触发“onBuildEnd”,因此 nodemon 可以按预期工作

    【讨论】:

      猜你喜欢
      • 2016-07-30
      • 1970-01-01
      • 2021-06-30
      • 1970-01-01
      • 2016-04-12
      • 2018-07-11
      • 2018-11-29
      • 2020-08-04
      • 1970-01-01
      相关资源
      最近更新 更多