Small problem when `publicPath` is empty
See original GitHub issueI’m having a small problem when trying to use this plugin with webpack’s publicPath
(from output config) as (''
- an empty string).
Problem
The asset generated is:
(note the first slash)
<link rel="manifest" href="/manifest.eb687d814aa4397c0e0ed4e8af308e43.json" />
Expected:
(without the first slash)
<link rel="manifest" href="manifest.eb687d814aa4397c0e0ed4e8af308e43.json" />
Why I need this:
My use case is that I don’t know - at build time - where from my assets will be served. I have an nginx that serves the html and will handle the paths to all assets (so, it will handle any assets served from any given path).
Possible Cause:
The code that is causing this is here: https://github.com/arthurbergmz/webpack-pwa-manifest/blob/9f59d8ce9407e6ead67d6ef486875e6e72ab8cf9/src/URI.js#L2
This is caused because you’re doing a simple array concatenation, so, it doesn’t handle empty values.
['', 'manifest.json']; // '/manifest.json' (my problem)
[1, 2, 3].join('/'); // 1/2/3
[1, '', 2, '', 3]; // 1//2//3
Possible Fix:
If you don’t see any problems, I think we can use nodejs’s path.join
:
path.join('', 'manifest.json'); // manifest.json
path.join('1', '2', '3'); // 1/2/3
path.join('1', '', '2', '', '3'); // 1/2/3
I also think that it’s more reliable to use path
module for those kind of file paths manipulation instead of doing this manually.
What do you think?
If you think it’s good, I can write a PR for that!
Thank you. Nice project btw! It solved our problems!
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
@arthurbergmz It’s working perfectly! Thank you!
Let me know when you publish a new version? So I can update my code! 😃
Hey @arthurbergmz, I’ll test it soon! Just give me some minutes!
Thank you.