-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong relative links in sub directory when a relative public url is specified #2786
Comments
Exactly the same problem, I just ran into. Happy to see soon some fixes on this matter. |
* replace d3-voronoi with delaunator * tsc commpiler might complain cause of @types/delaunator @types/delaunator version 3.0 is coming soon and will fix it * examples/src folder cannot have subfolder as relative paths are buggy in parcel-bundler (parcel-bundler/parcel#2786) * add examples/README.md
Same issue. @codingphil how are you working around this currently? Just putting everything in the root? |
I'm currently using a self built version of parcel with my pull request included ;-) |
There's a merged PR, but I'm still seeing this behaviour with Parcel 2. |
@thewilkybarkid Can provide a code sample with Parcel 2? |
Using Parcel 2 on the original code sample still breaks: |
@thewilkybarkid Why are you using |
@codingphil Is your self-built version of parcel public somewhere? I noticed you said "with my pull request included", but I didn't really understand that part. We have this same problem and are looking for a fix. |
@Aaronius No. Sorry. I just checked the source with my pull request out locally, changed the version number so that it didn't conflict with the public version, built it and published it to the company internal npm repo. Then I referenced this exact version from the project where I used parcel. This pull request does not work for parcel v2, of course. |
Oh, I think you're talking about this pull request. Thanks @codingphil. So it looks like that PR was never released (at least under 1.x). This gives me something to work with. Thanks. |
Yes. I was not able to get the tests green (they were kind of flaky - unrelated tests failed). |
Yeah, that fixed our problem. It fixed another problem we were having as well, which is that when we specified a Thank you for your work on this! |
Is there any development on this? I'm also facing this bug. Here is my dist
├── index.9fdc10c0.css
├── index.9fdc10c0.css.map
├── index.b1d22321.js
├── index.b1d22321.js.map
├── index.html
└── pages
├── blogs
│ └── mistakes.html
├── blogs.a8089d62.css
├── blogs.a8089d62.css.map
└── blogs.html In <link rel="stylesheet" href="index.9fdc10c0.css" /> But in my <link rel="stylesheet" href="pages/blogs.a8089d62.css" /> Which is wrong. Instead of Here is my {
"name": "portfolio",
"version": "1.0.0",
"author": "shasherazi",
"license": "WTFPL",
"source": "./src/index.html",
"scripts": {
"start": "parcel",
"dev": "parcel serve --open",
"prebuild": "rm -rf dist",
"build": "parcel build './**/*.html' --public-url ./",
"deploy": "npm run build && echo shasherazi.me > ./dist/CNAME && gh-pages -d dist"
},
"devDependencies": {
"eslint": "^7.32.0 || ^8.2.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.25.2",
"gh-pages": "^5.0.0",
"hint": "^7.1.3",
"parcel": "^2.8.3",
"typescript": "^4.9.5"
},
"repository": "git@github.com:shasherazi/portfolio.git"
} |
🐛 bug report
This bug is related to the issue #2774
and also to this pull request: #2740
If you specify the parameter
--public-url ./
when calling the parcel cli (like it is described in the doc for the cli) the relative links (e.g. hrefs) are relative to the root directory and not relative to the sub directory in which the bundle/html file is located.repro-html-in-subdir.zip
🎛 Configuration (.babelrc, package.json, cli command)
See attached project above.
🤔 Expected Behavior
After you call
yarn build
in the output directorydist
there is the filesubdir1/subdirpage.html
.The content of the file should be:
The bundle resulting from the file
subdir1/subdirpage.js
issubdirpage.7501a095.js
which currently is located in the root dist folder.The file
subdirpage2.html
is located in the same folder assubdirpage.html
the the relative link should reflect this fact.😯 Current Behavior
The content of the bundled file
subdir1/subdirpage.html
is the following:As you see the URL of the href to the file
subdirpage2.html
which is in the same folder assubdirpage.html
is wrong (does not point to the current folder).Also the link to the bundled JavaScript file
subdirpage.7501a095.js
which is located in the root dist folder does not point to the parent folder.💁 Possible Solution
In my opinion in the method
Asset.replaceBundleNames()
(/packages/core/parcel-bundler/src/Asset.js
) the relative URL should be calculated based on the directory of the parent bundle path (like the path which is calculated here:https://github.com/parcel-bundler/parcel/blob/parcel-bundler%401.12.1/packages/core/parcel-bundler/src/Bundle.js#L162).
The parent bundle in the example above is
subdir1/subdirpage.html
.This should be only be done if the replaced bundle path is relative and the value of the publicURL option is a relative url (like
./
).🔦 Context
We as a dev team want to structure our web application by putting HTML files and JavaScript files of parts of the site into sub directories. This is currently only possible for JavaScript files but not for HTML file because of this bug.
The example project attached to this issue is an abstract representation of our web application.
💻 Code Sample
repro-html-in-subdir.zip
🌍 Your Environment
The text was updated successfully, but these errors were encountered: