New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom vite middleware is not executed for CSS files #27110
Comments
Are you using the Would it be possible to provide an example of what you are attempting? |
We're using custom builder to pass additional middleware. themeAssets.map(
(asset: string): NextHandleFunction =>
function (req, res, next) {
if (req.url?.includes(`/assets/${asset}`)) {
const theme = parseThemeName(req)
if (theme) {
res.writeHead(302, {
location: `/assets/context/${theme}/${asset}`,
})
res.end()
return
}
}
next()
},
)
We'd like to use the same approach for |
Ideally, this should be possible with a customized proxy configuration file. I'll see if I can put together an example. Are you using the customized builder for anything beyond the additional middleware? |
It seems to work for images or other static assets, but doesn't for CSS files. I've even tried to "catch-all" requests with: export default {
'/': {
bypass: function (req, res, proxyOptions) {
console.log(req.url)
},
},
} When you visit
Yes, we also provide some esbuild plugins - mostly to replace some placeholders (using |
Command
serve
Description
We are in the process of migrating from using webpack to esbuild/vite.
For development purposes, we need a way to dynamically switch from one theme to another. At this point, we have achieved it by proxying CSS or image files depending on the host name.
After switching to Vite, it turned out that it could work the same, apart from the fact that for CSS resources, our middleware is never executed.
I found a piece of code that seems to be the root cause. The
AngularMemoryPlugin
handles CSS files in a specific way and never executesnext()
, which terminates the middleware chain.angular-cli/packages/angular_devkit/build_angular/src/tools/vite/angular-memory-plugin.ts
Lines 163 to 178 in 3d7b5f7
Describe the solution you'd like
Ideally middleware chain should not be terminated in
AngularMemoryPlugin
for stylesheets (ie.next()
should be called)Describe alternatives you've considered
In the worst case scenario, we will find another solution for our use case. However, since the issue only pertains to CSS files, it would be really helpful if the middleware is executed for these files as well.
The text was updated successfully, but these errors were encountered: