question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Small problem when `publicPath` is empty

See original GitHub issue

I’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:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
wmartinscommented, Aug 10, 2017

@arthurbergmz It’s working perfectly! Thank you!

Let me know when you publish a new version? So I can update my code! 😃

1reaction
wmartinscommented, Aug 9, 2017

Hey @arthurbergmz, I’ll test it soon! Just give me some minutes!

Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack5 Automatic publicPath is not supported in this browser
The error is caused by a bug in mini-css-extract-plugin 1.3.8 and lower in combination with Webpack 5. It is triggered when a stylesheet ......
Read more >
Public Path - webpack
The publicPath configuration option can be quite useful in a variety of scenarios. It allows you to specify the base path for all...
Read more >
Webpack — Understanding the 'publicPath' mystery - Medium
The 2 main issues which are caused by incorrect publicPath config configuration are : webpack-dev-server : live-reload feature doesn't work ...
Read more >
Tutorial - A Guide to Module Federation for Enterprise
I documented these issues and fixes so you can avoid these pitfalls. ... A promising option involves leveraging Webpack's publicPath : auto ...
Read more >
How to configure CSS Modules for webpack - LogRocket Blog
This increase in size can lead to loads of problems, like trying to ... In short, CSS Modules are component-based stylesheets that allow...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found