【问题标题】:ASP.NET Core: how to run npm script command in startup.cs file?ASP.NET Core:如何在 startup.cs 文件中运行 npm 脚本命令?
【发布时间】:2019-12-17 18:07:16
【问题描述】:

在asp.net core 2.1中启动程序时,有什么方法可以运行package.json文件中定义的npm命令?

例如:

startup.cs:

 if (env.IsDevelopment()) {
   ABCMiddleware(npmScript: "build");
 }

和 package.json:

"scripts": {
    "build": "webpack",
  },

【问题讨论】:

    标签: asp.net-core npm


    【解决方案1】:

    一个简单的方法是

    if (env.IsDevelopment()) {
      // path may be different on different machines
      string yarnPath = "c:\\Program Files (x86)\\Yarn\\bin\\yarn.cmd";
      Process.Start(yarnPath, "build");
    }
    

    如需更多控制,ProcessStartInfo docs 显示其他运行方式

    【讨论】:

      猜你喜欢
      • 2021-07-22
      • 1970-01-01
      • 2019-11-30
      • 1970-01-01
      • 1970-01-01
      • 2023-01-17
      • 2020-11-28
      • 2017-05-10
      • 1970-01-01
      相关资源
      最近更新 更多