运行 视觉工作室 运行 上的 Webpack-dev-server - .net 核心项目
Running Webpack-dev-server on run in visual studios - .net core project
我正在尝试设置我的环境,所以当我在 Visual Studio 2015 中单击 运行 时,它将安装我的节点模块,然后 运行 前端 webpack-开发服务器。
我加了
"precompile": [ "yarn install", "yarn run start" ]
到我的 scripts
在我的 project.json
If you want to see the Start Script that I'm running:
https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/scripts/start.js
有点用。它会启动服务器,但不会在浏览器中打开它,它有点破坏 VS 到我无法停止调试的地步,也无法关闭 VS,因为它正在调试。
所以无论如何我可以按照我想要的方式完成这项工作,还是我应该使用 cmd 来启动 webpack-dev-server?
我刚试过:
"precompile": [ "yarn install", "start cmd /k yarn run start" ]
希望我能让 VS 打开命令提示符和 运行 启动脚本,但这没有用。
我找到了答案。将保持开放状态,看看是否有人有更好的解决方案。
在我的 Startup.cs 我添加了:
Process.Start("CMD.exe", "/K yarn run start");
Process.Start("cmd", "/C start http://localhost:3000");
第一行 运行 在 cmd 中使用我的命令,第二行在我的 webpack-dev-server 端口打开我的默认浏览器。
第二个解决方案可能会根据用例起作用。
下载 node tools for VS 并在您的解决方案中创建一个新的空 Node 项目。您可以转到项目的属性,那里有一个名为 Script (startup file)
的输入。您可以将其指向您的启动脚本,在我的例子中是 scripts/start.js
这是我想出的解决方案:
In my Startup.cs I added:
Process.Start("CMD.exe", "/K yarn run start");
Process.Start("cmd", "/C start http://localhost:3000");
The first line running my command in cmd, and the second opening my
default browser at the port of my webpack-dev-server.
第二个解决方案可能会根据用例起作用。
Download the node tools for VS and create a new empty Node
project in your solution. You can go to the project's properties and
there's an input called Script (startup file)
. You can point that to
your start up script, in my case it was scripts/start.js
安装 Command Task runner,这将允许您 运行 对特定事件发出命令。
在新的 commands.json
文件中,定义如下脚本:
{
"commands": {
"InstallPackages": {
"fileName": "cmd.exe",
"workingDirectory": ".",
"arguments": "/K yarn run start"
},
"OpenSite": {
"fileName": "cmd.exe",
"workingDirectory": ".",
"arguments": "/C start http://localhost:3000"
}
},
"-vs-binding": { "AfterBuild": [ "InstallPackages", "OpenSite" ] }
}
您还可以删除 "-vs-binding"
行并通过 Task Runner Explorer 手动进行绑定 UI。
这胜过更改代码以每次显式启动网络服务器。
我应该补充一点,我发现当 Web 服务器的命令提示符 window 仍然打开时,Visual Studio 不会退出。我想这很公平,但它让我抓狂了几次(我以这种方式启动 Web 服务器并将其保留 运行ning)。简单的解决方案是关闭 Web 服务器 window,VS 将正常关闭而无需进一步提示。
另一种方法是通过将其启动绑定到 Task Runner Explorer 中的 Project Open 绑定来启动 webpack 开发服务器,而不是 After Build 绑定。以这种方式,在您使用 Visual Studio.
构建解决方案之前,webpack 开发服务器已经 运行ning
这种方式的好处是不会挂掉VS构建顺序,因为webpack服务器进程还在运行ning
我使用 VS NPM Task Runner 扩展来进行绑定并有一个 NPM 脚本命令,如:
"watch": "webpack-dev-server --hot --inline"
然后我将脚本绑定到 Project Open 绑定
您还可以将 yarn install
命令作为项目打开 运行 的 NPM 脚本的一部分。
我正在尝试设置我的环境,所以当我在 Visual Studio 2015 中单击 运行 时,它将安装我的节点模块,然后 运行 前端 webpack-开发服务器。
我加了
"precompile": [ "yarn install", "yarn run start" ]
到我的 scripts
在我的 project.json
If you want to see the Start Script that I'm running: https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/scripts/start.js
有点用。它会启动服务器,但不会在浏览器中打开它,它有点破坏 VS 到我无法停止调试的地步,也无法关闭 VS,因为它正在调试。
所以无论如何我可以按照我想要的方式完成这项工作,还是我应该使用 cmd 来启动 webpack-dev-server?
我刚试过:
"precompile": [ "yarn install", "start cmd /k yarn run start" ]
希望我能让 VS 打开命令提示符和 运行 启动脚本,但这没有用。
我找到了答案。将保持开放状态,看看是否有人有更好的解决方案。
在我的 Startup.cs 我添加了:
Process.Start("CMD.exe", "/K yarn run start");
Process.Start("cmd", "/C start http://localhost:3000");
第一行 运行 在 cmd 中使用我的命令,第二行在我的 webpack-dev-server 端口打开我的默认浏览器。
第二个解决方案可能会根据用例起作用。
下载 node tools for VS 并在您的解决方案中创建一个新的空 Node 项目。您可以转到项目的属性,那里有一个名为 Script (startup file)
的输入。您可以将其指向您的启动脚本,在我的例子中是 scripts/start.js
这是我想出的解决方案:
In my Startup.cs I added:
Process.Start("CMD.exe", "/K yarn run start"); Process.Start("cmd", "/C start http://localhost:3000");
The first line running my command in cmd, and the second opening my default browser at the port of my webpack-dev-server.
第二个解决方案可能会根据用例起作用。
Download the node tools for VS and create a new empty Node project in your solution. You can go to the project's properties and there's an input called
Script (startup file)
. You can point that to your start up script, in my case it wasscripts/start.js
安装 Command Task runner,这将允许您 运行 对特定事件发出命令。
在新的 commands.json
文件中,定义如下脚本:
{
"commands": {
"InstallPackages": {
"fileName": "cmd.exe",
"workingDirectory": ".",
"arguments": "/K yarn run start"
},
"OpenSite": {
"fileName": "cmd.exe",
"workingDirectory": ".",
"arguments": "/C start http://localhost:3000"
}
},
"-vs-binding": { "AfterBuild": [ "InstallPackages", "OpenSite" ] }
}
您还可以删除 "-vs-binding"
行并通过 Task Runner Explorer 手动进行绑定 UI。
这胜过更改代码以每次显式启动网络服务器。
我应该补充一点,我发现当 Web 服务器的命令提示符 window 仍然打开时,Visual Studio 不会退出。我想这很公平,但它让我抓狂了几次(我以这种方式启动 Web 服务器并将其保留 运行ning)。简单的解决方案是关闭 Web 服务器 window,VS 将正常关闭而无需进一步提示。
另一种方法是通过将其启动绑定到 Task Runner Explorer 中的 Project Open 绑定来启动 webpack 开发服务器,而不是 After Build 绑定。以这种方式,在您使用 Visual Studio.
构建解决方案之前,webpack 开发服务器已经 运行ning这种方式的好处是不会挂掉VS构建顺序,因为webpack服务器进程还在运行ning
我使用 VS NPM Task Runner 扩展来进行绑定并有一个 NPM 脚本命令,如:
"watch": "webpack-dev-server --hot --inline"
然后我将脚本绑定到 Project Open 绑定
您还可以将 yarn install
命令作为项目打开 运行 的 NPM 脚本的一部分。