【问题标题】:build script don't runs when creating a Node.js and React app in Visual Studio在 Visual Studio 中创建 Node.js 和 React 应用程序时构建脚本不运行
【发布时间】:2020-04-19 08:45:31
【问题描述】:

我按照分步指南配置 Visual Studio 2019 以开发 Node.js-React 应用程序。 指南在这里: https://docs.microsoft.com/en-us/visualstudio/javascript/tutorial-nodejs-with-react-and-jsx?view=vs-2019

简而言之,该指南告诉配置应在 Visual Studio 编译时触发的 npm 脚本(称为“build”),以便使用包含 react 组件的 app.tsx 通过 typescript 生成 app-bundle.js . 这必须通过将以下代码添加到 package.json 来完成

"scripts": {
    "build": "webpack-cli app.tsx --config webpack-config.js" 
}

但是它不起作用,因为当我在 app.tsx 中更改某些内容并运行 Visual Studio 调试器时,网页根本不会更改。

如果我使用 nuget 包控制台运行以下命令

npm run-script build

然后它工作正常!

那么,这是 VS2019 的错误,还是我错过了一些技巧?

非常感谢您的帮助

【问题讨论】:

  • 作为一个 js 开发者,你可以使用 vs code 而不是使用 Visual Studio,它更容易:)
  • 我可以试试,但我有 VS2019 的企业许可证。我应该使用它
  • 我对 Visual Studio 了解不多,但由于它是一个编辑器,所以会很相似,所以让我总结一下,你需要一个 react js 和 node js 项目。所以首先是安装 node 和 npm,之后为了方便你可以使用 npm i -g create-react-app 安装 create react app,g(g 标志是全局的),然后在你的驱动器中创建一个文件夹作为 Sample,在里面该文件夹使用终端运行 create-react-app 客户端,它将安装您的反应应用程序名称作为客户端(您希望使用任何您想要的名称 - 不要使用大写它不会起作用),
  • 之后在 Sample 文件夹中创建一个名为 server 的文件夹,在 server 文件夹中执行 npm init -y (-y 标志表示全部是),然后安装 npm i express,然后参考文档以获得简单服务器在服务器文件夹中公开一个端口并使用 npm run start 运行它(在 package.json 中添加脚本)并转到客户端文件夹 npm start 就是这样,节点将在 5000 中运行(您在代码中提到的任何端口)并做出反应以 3000 运行(默认)
  • 你试过这种方式吗?如果您使用上述方式,您可以在 Visual Studio 中打开示例文件夹,然后您可以开始编码,以便客户端和服务器都在那里,请告诉我,以便我添加快速刷新所需的步骤,全部作为答案

标签: node.js reactjs typescript npm visual-studio-2019


【解决方案1】:

我也遇到过类似的问题。 我通过visual studio 2017,2019的这个未记录的功能解决了这个问题:

BY manual editing, 
 You can add the following post-build event to package.json
 "-vs-binding": { "AfterBuild": [ "build" ] }

by GUI, 
  in task runner explorer window, 
   select "build" task and let popup context menu open using right-mouse-button,
    select bindings -> After build (make its preceding check box on)
  this will add "-vs-binding" property to your package.json

Either one is okay. This  works on vs 2017 and may works on vs 2019 either.

VS2017,2019 nodejs project build process seems 
  not to actually call my "build" script at all.
we should specify the "build" script as post-build event 
  for vs default nodejs build action.
It seems weired. I hope Microsoft solve this fault using  patches.

task runner explorer capture image

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-02
    • 2019-10-02
    • 1970-01-01
    • 2017-06-09
    • 1970-01-01
    • 1970-01-01
    • 2018-05-01
    • 2022-08-02
    相关资源
    最近更新 更多