critters icon indicating copy to clipboard operation
critters copied to clipboard

Fails to locate css for html files in subdirectories

Open Ansimorph opened this issue 6 years ago • 3 comments
trafficstars

The html file generated is in a subdirectory of the main output directory (/project-root/dist/): /project-root/dist/imprint/index.html

The css is located in the output directory: /project-root/dist/styles.css

So the html generated by webpack references relatively: <link href="../styles.css" rel="stylesheet">

Critters resolves this as follows: filename = path.resolve(outputPath, href.replace(/^\//, ""));

Leading to path.resolve(/project-root/dist/../styles.css); which generates the non-existant /project-root/styles.css

This is broken, because it tries to resolve relatively to the main output directory and not the real location of the html-file.

Ansimorph avatar Dec 04 '18 05:12 Ansimorph

Setting a public path in webpack can circumvent the problem, because it generates absolute urls:

output: { publicPath: "/" }

Ansimorph avatar Dec 07 '18 12:12 Ansimorph

Nice catch! I always use publicPath since without it, client-side routing breaks resource paths. This should be pretty simple to fix.

developit avatar Dec 11 '18 03:12 developit

+1

tlambrou avatar Feb 14 '19 21:02 tlambrou