You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes, it's useful to include external resources which are located on the same server but not actually part of the project. For example, a stylesheet is located at https://example.com/styles.css and you want to include it in your website at https://example.com/my-project/. The normal way to do this is to use an absolute path, e.g. <link rel="stylesheet" href="/styles.css">. However, this doesn't work with Parcel, because it will try to resolve the path relative to the project root while bundling.
Proposed solution
Add a URL scheme which forces Parcel to not process the path. For example, the path in <link rel="stylesheet" href="ignore:/styles.css"> would not be processed by Parcel, and the browser would request the file directly from the server. In other words, the block of code above will be transformed to <link rel="stylesheet" href="/styles.css"> in the output without any processing of the linked file.
Example
<linkrel="stylesheet" href="ignore:/styles.css">
is transformed to
<linkrel="stylesheet" href="/styles.css">
Implementation
The implementation should be fairly simple. It only requires 4 lines of code. I've already implemented it and tested it locally, and it works as expected. I'll submit a PR soon once I've got a feedback from the maintainers.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Motivation
Sometimes, it's useful to include external resources which are located on the same server but not actually part of the project. For example, a stylesheet is located at
https://example.com/styles.css
and you want to include it in your website athttps://example.com/my-project/
. The normal way to do this is to use an absolute path, e.g.<link rel="stylesheet" href="/styles.css">
. However, this doesn't work with Parcel, because it will try to resolve the path relative to the project root while bundling.Proposed solution
Add a URL scheme which forces Parcel to not process the path. For example, the path in
<link rel="stylesheet" href="ignore:/styles.css">
would not be processed by Parcel, and the browser would request the file directly from the server. In other words, the block of code above will be transformed to<link rel="stylesheet" href="/styles.css">
in the output without any processing of the linked file.Example
is transformed to
Implementation
The implementation should be fairly simple. It only requires 4 lines of code. I've already implemented it and tested it locally, and it works as expected. I'll submit a PR soon once I've got a feedback from the maintainers.
Related issues
Beta Was this translation helpful? Give feedback.
All reactions