将Webpack构建与ASP.NET Core 3.0集成的最佳方法? [英] Best way to integrate webpack builds with ASP.NET Core 3.0?

查看:467
本文介绍了将Webpack构建与ASP.NET Core 3.0集成的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将我的ASP.NET Core应用程序升级到V3,并使用Visual Studio 2019进行开发/调试.除此之外,整个过程很顺利:

I'm upgrading my ASP.NET Core app to V3, and using Visual Studio 2019 for development / debugging. The process has been smooth except for this:

public void Configure(…..
                app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
                {
                    HotModuleReplacement = false,
                    ReactHotModuleReplacement = false
                });

UseWebpackDevMiddleware不再是: https://github.com/aspnet/AspNetCore/issues/12890 .

UseWebpackDevMiddleware is no more: https://github.com/aspnet/AspNetCore/issues/12890 .

我现在希望了解每次调试时VS运行webpack的最佳方法,最好是仅在已更改的JS代码上运行.这就是我从UseWebpackDevMiddleware获得的值.我的应用程序是React应用程序,如果您的应用程序是从CreateReactApp启动的,则似乎有一些新的替代品,但我的不是. (我相信以此为出发点但然后分开的应用程序称为弹出".)即使我的应用程序未利用CreateReactApp,我是否仍可以某种方式利用该工具的优势呢?另外,在启动新的React应用程序之后,CreateReactApp的作用是什么?我以为它只会在第一次使用时就使模板代码膨胀.

I'm now looking to understand the best way to have VS run webpack every time I debug, ideally only on JS code that has changed. This was the value I was getting from UseWebpackDevMiddleware. My app is a React app, and it seems like there is some new replacement for this if your app was started from CreateReactApp, but mine was not. (I believe apps that stated from this but then separated are called "ejected.") Is it somehow possible for me to still take advantage of whatever that facility is, even though my app does not leverage CreateReactApp? Also, what is the role of CreateReactApp after it bootstraps your new React application? I imagined it would be only used for inflating template code at the first go.

Microsoft.AspNetCore.SpaServices.Extensions在所有这些中的作用是什么?

What is the role of Microsoft.AspNetCore.SpaServices.Extensions in all of this?

我不需要热模块更换;我不需要服务器端预渲染.我实际上只是在试图了解如何使我的JS(通过Webpack)透明地构建(作为Web调试过程的一部分).我可以将其连接到MSBuild吗?我认为其他人在升级时将面临相同的问题.

I don't need hot module replacement; I don't need server side prerendering. I'm really just trying to understand how to get my JS to transparently build (via Webpack) as part of my debugging process. Is this something that I could hook into MSBuild for? I imagine others are going to face the same question as they upgrade.

谢谢您的建议.

推荐答案

您提到VS.我的解决方案适用于Visual Studio,但不适用于VS Code.

我使用WebPack Task Runner: https://marketplace.visualstudio.com/items ?itemName = MadsKristensen.WebPackTaskRunner

I use WebPack Task Runner: https://marketplace.visualstudio.com/items?itemName=MadsKristensen.WebPackTaskRunner

这会将webpack.config.js任务添加到Visual Studio的任务运行器资源管理器"中,然后您可以将这些任务绑定到诸如构建前"或构建后"之类的事件

This adds webpack.config.js tasks into the "Task Runner Explorer" in Visual Studio, and you can then bind those tasks to events like "Before Build" or "After Build"

这篇关于将Webpack构建与ASP.NET Core 3.0集成的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆