WebOptimizer icon indicating copy to clipboard operation
WebOptimizer copied to clipboard

AdjustRelativePaths still get urls wrong on NuGet staticwebassets

Open Daeymon opened this issue 5 years ago • 3 comments

When running in localhost for debugging, the url's of NuGet packages with staticwebassets still are being given the wrong relative url. The following small change in the ExecuteAsync method in RelativePathAdjuster.cs fixes this, but I'm not sure if it breaks other scenarios that the current way of doing it covers.

foreach (string key in config.Content.Keys) { string inputPath = Path.Combine(env.WebRootPath, key.TrimStart('/')); string outputPath = Path.Combine(env.WebRootPath, config.Asset.Route.TrimStart('/')); content[key] = Adjust(config.Content[key].AsString(), inputPath, outputPath); }

Daeymon avatar Jul 28 '20 15:07 Daeymon

I can confirm this fixes my issue as well. I have a Razor Class library that has css/js assets that are served as static files (wwwroot-folder and /_content/-url) and the relative paths in those css-files did not get altered properly before this fix.

I'll generate pull request, lets see what happens :)

Elimi81 avatar Oct 23 '20 05:10 Elimi81

I'm currently running into this.

I've just modified my project to be able to support SCSS. Webpack now builds .scss files and outputs them as .css files into /dist/.

Since version 5, Webpack has the habit of copying css-referred images into the /dist/ folder, as well. The outputted .css files refer to these image files relatively.

So that's just the filename, since the .css files and their images are in the same dir.

When I inline a css file in a page in the root, then it will try to find the image there, as well. But it's in dist.

Is WebOptimizer supposed to figure out, on the fly, in which path it's running, and then adjust the relative css image paths?

If so, then it isn't working, currently.

Maybe this isn't even a Web Optimizer problem, but a Webpack (or my configuration of it) problem.

Configuring Webpack so that it would use relative image paths (and not copying images to dist), would also solve the problem.

Is this the better avenue to go down?

jwbats avatar Mar 04 '23 18:03 jwbats

I fixed my problem by having the css-loader not process css image path urls.

jwbats avatar Mar 05 '23 00:03 jwbats