使用 ASP.NET Core 3.1 和 Node.js?
Using ASP.NET Core 3.1 with Node.js?
我读过NodeServices have been deprecated for ASP.NET Core 3.1。是否仍然可以使用 Node.js 将我的 JavaScript 文件构建到 wwwroot
中的 dist
文件夹中?
根据 NodeServices package, it allows you to "invoke Node.js modules at runtime in ASP.NET Core applications" (emphasis my own). This is reiterated in more detail on the GitHub ReadMe:
This NuGet package provides a fast and robust way to invoke Node.js code from a .NET application (typically ASP.NET Core web apps). You can use this whenever you want to use Node/NPM-supplied functionality at runtime in ASP.NET.
这完全独立于例如在 构建时间 .
预编译、最小化或移动 JavaScript 文件
构建时间任务
你不需要——也不会——需要 NodeServices 来下载 npm 包依赖:
- 本地工作站上的命令提示符,
- 来自Visual Studio的内置集成,或
- 来自构建服务器上的任务(例如,Azure Pipelines 上的
npm
任务)。
同样,要预编译、最小化客户端依赖项并将其从源目录移动到分发目录,您可以(继续?)使用像 Gulp.js[=50 这样的工具=]、Grunt 或 WebPack,它们都是在 Node.js.
之上运行的构建系统
Important: The critical distinction here is that you don't need to call these tools at runtime from your .NET application. You are incorporating the output from your Node.js build tools into your .NET application, but you aren't executing Node.js code as part of your .NET application.
唯一的例外是您使用 NodeService 在运行时动态执行这些构建任务。例如,如果您的应用程序配置了 UseWebpackDevMiddleware()
,那么它将不再有效。在这种情况下,您需要迁移到部署之前(或期间)发生的构建过程。
Webpack
如果您正在使用UseWebpackDevMiddleware()
,那么我建议您考虑配置Webpack locally. That should be a pretty seamless transition. You can run it manually via the Webpack CLI, use a Visual Studio extension, or potentially even integrate it into your build process. Personally, I run it manually on my development server, then integrate it into my Azure Pipelines build process。
或者,如果你真的想保持对 Webpack 文件的“及时”构建支持,你可以考虑使用 Webpack dev server in conjunction with ASP.NET Core, as discussed in .
我读过NodeServices have been deprecated for ASP.NET Core 3.1。是否仍然可以使用 Node.js 将我的 JavaScript 文件构建到 wwwroot
中的 dist
文件夹中?
根据 NodeServices package, it allows you to "invoke Node.js modules at runtime in ASP.NET Core applications" (emphasis my own). This is reiterated in more detail on the GitHub ReadMe:
This NuGet package provides a fast and robust way to invoke Node.js code from a .NET application (typically ASP.NET Core web apps). You can use this whenever you want to use Node/NPM-supplied functionality at runtime in ASP.NET.
这完全独立于例如在 构建时间 .
预编译、最小化或移动 JavaScript 文件构建时间任务
你不需要——也不会——需要 NodeServices 来下载 npm 包依赖:
- 本地工作站上的命令提示符,
- 来自Visual Studio的内置集成,或
- 来自构建服务器上的任务(例如,Azure Pipelines 上的
npm
任务)。
同样,要预编译、最小化客户端依赖项并将其从源目录移动到分发目录,您可以(继续?)使用像 Gulp.js[=50 这样的工具=]、Grunt 或 WebPack,它们都是在 Node.js.
之上运行的构建系统Important: The critical distinction here is that you don't need to call these tools at runtime from your .NET application. You are incorporating the output from your Node.js build tools into your .NET application, but you aren't executing Node.js code as part of your .NET application.
唯一的例外是您使用 NodeService 在运行时动态执行这些构建任务。例如,如果您的应用程序配置了 UseWebpackDevMiddleware()
,那么它将不再有效。在这种情况下,您需要迁移到部署之前(或期间)发生的构建过程。
Webpack
如果您正在使用UseWebpackDevMiddleware()
,那么我建议您考虑配置Webpack locally. That should be a pretty seamless transition. You can run it manually via the Webpack CLI, use a Visual Studio extension, or potentially even integrate it into your build process. Personally, I run it manually on my development server, then integrate it into my Azure Pipelines build process。
或者,如果你真的想保持对 Webpack 文件的“及时”构建支持,你可以考虑使用 Webpack dev server in conjunction with ASP.NET Core, as discussed in