Node.js 在.NET核心构建过程中运行Web包开发服务器
好的,在过去的几天里,我一直在绞尽脑汁想弄明白这一点,而VisualStudio似乎让这条路变得更加困难 我希望我的.NET CORE应用程序在调试时在webpack dev服务器上运行我的Vue.js应用程序,否则构建生产版本并将其放入它输出的文件结构中。。。您可能认为我可以添加一个构建后事件,如下所示:Node.js 在.NET核心构建过程中运行Web包开发服务器,node.js,visual-studio,webpack,asp.net-core,vue.js,Node.js,Visual Studio,Webpack,Asp.net Core,Vue.js,好的,在过去的几天里,我一直在绞尽脑汁想弄明白这一点,而VisualStudio似乎让这条路变得更加困难 我希望我的.NET CORE应用程序在调试时在webpack dev服务器上运行我的Vue.js应用程序,否则构建生产版本并将其放入它输出的文件结构中。。。您可能认为我可以添加一个构建后事件,如下所示: if $(ConfigurationName) == 'Debug' { npm run dev } 但一旦进入webpack进程,IIS服务器的构建就永远不会继续,它只是在web
if $(ConfigurationName) == 'Debug' {
npm run dev
}
但一旦进入webpack进程,IIS服务器的构建就永远不会继续,它只是在webpack服务器说它正在运行后永远挂起。我想是因为没有任何东西可以告诉VisualStudio这个过程已经完成了?如果我运行npm run build
来构建默认的生产构建,同样的情况也会发生。然后停止生成的唯一方法是在单独的终端实例中使用taskkill/F/IM Node.exe
杀死节点的所有实例
我可以在VisualStudio之外运行这些命令,它们工作得很好,但是将它们插入VS构建过程根本不起作用
或者,我尝试加载.NET CORE Vue.js模板并复制其功能,以便在.csproj
文件中构建应用程序,并对其进行编辑以满足我的需要:
<Target Name="DebugRunWebpack" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' ">
<!-- Ensure Node.js is installed -->
<Exec Command="node --version" ContinueOnError="true">
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
</Exec>
<Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
<!-- In development, the dist files won't exist on the first run or when cloning to
a different machine, so rebuild them if not already present. -->
<Message Importance="high" Text="Running dev server..." />
<Exec Command="node node_modules/webpack/bin/webpack.js" />
</Target>
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec Command="npm install" />
<Exec Command="node node_modules/webpack/bin/webpack.js --env.prod" />
<!-- Include the newly-built files in the publish output -->
<ItemGroup>
<DistFiles Include="wwwroot\js\**" />
<ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
<RelativePath>%(DistFiles.Identity)</RelativePath>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</ResolvedFileToPublish>
</ItemGroup>
</Target>
%(DistFiles.Identity)
保存最新
这将正确地构建文件(基本上与npm run build
相同),但从未运行过开发服务器
仅仅使用预构建的NPM命令,必须有一种更简单的方法来实现这一点,但是我在StackOverflow上找到的所有解决方案都不起作用,而且应该是一个简单的解决方案变得比必须的更加困难
有什么想法吗\ 所以,经过大量的谷歌搜索,我认为我有了一个不错的解决方案,它将微软的解决方案与我自己的NPM脚本结合在一起:
<Target Name="RunWebpackServer" AfterTargets="Publish" Condition=" '$(Configuration)' == 'Debug' ">
<!-- Check if Node.js / NPM is installed -->
<Exec Command="node --version" ContinueOnError="false">
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
</Exec>
<!-- If there's an error, tell the user to install Node -->
<Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
<!-- Clean cache, install packages and run the dev server -->
<Message Importance="high" Text="Cleaning NPM Cache..." />
<Exec Command="npm cache clean" />
<Message Importance="high" Text="Installing NPM Packages..." />
<Exec Command="npm install" />
<Message Importance="high" Text="Running Webpack Dev Server..." />
<Exec Command="npm run dev" />
</Target>
现在,有人知道如何在调试停止时关闭Node dev服务器吗?如果我继续停止并运行,我会得到大量的节点实例,这些实例会让系统陷入困境。因此,经过大量的谷歌搜索,我认为我有了一个不错的解决方案,它将微软的解决方案与我自己的NPM脚本结合在一起:
<Target Name="RunWebpackServer" AfterTargets="Publish" Condition=" '$(Configuration)' == 'Debug' ">
<!-- Check if Node.js / NPM is installed -->
<Exec Command="node --version" ContinueOnError="false">
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
</Exec>
<!-- If there's an error, tell the user to install Node -->
<Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
<!-- Clean cache, install packages and run the dev server -->
<Message Importance="high" Text="Cleaning NPM Cache..." />
<Exec Command="npm cache clean" />
<Message Importance="high" Text="Installing NPM Packages..." />
<Exec Command="npm install" />
<Message Importance="high" Text="Running Webpack Dev Server..." />
<Exec Command="npm run dev" />
</Target>
现在,有人知道如何在调试停止时关闭Node dev服务器吗?如果我继续停止并运行,我会得到大量的节点实例,这些实例会使系统陷入困境