-
Notifications
You must be signed in to change notification settings - Fork 58
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
Configure url path for internal extension html page #115
Comments
Short answer: Put the entry point relative to the Vite root where you want it in the final output. There is no other official way. So right now your project looks like this:
You can't achieve Put your onboarding.html file inside your vite root, which appears to be the project root.
As of right now, there is not an officially supported way to customize the runtime paths of entry points, so moving the source file to a different path relative to the Vite root is the only solution. Personally, I prefer a very flat directory structure ( That said, because the extension ID is random, people aren't going to type your onboarding url in the search box, and the path is less important. It may not be appealing to see That said, if you really want to customize this, you could open a PR to add support, |
Update: I've figured out how to do this. You just have to move the file after the build is finished. All the CSS and script references are absolute paths, so you don't need to worry about updating the HTML files at all. If you update the rollup bundle, the manifest will also be generated with the correct Here's a custom plugin that does this: import fs from 'fs-extra';
export default defineConfig({
plugins: [
browserExtension({
manifest: "src/manifest.json",
browser: process.env.TARGET ?? "chrome",
htmlViteConfig: {
plugins: [
{
name: "html-rename",
async writeBundle(_, bundle) {
// Update the bundle so the manifest gets generated correctly
bundle["popup.html"] = {
...bundle["src/popup/index.html"];
fileName: "popup.html"
}
delete input["src/popup/index.html"];
// Actually move the file
await fs.move("dist/src/popup/index.html", "dist/popup.html");
},
},
],
},
})
]
}); |
If I have time, or someone creates a PR, we could do this automatically for everyone, maybe with an options like this: export default defineConfig({
plugins: [
browserExtension({
entrypointsPaths: {
"src/popup/index.html": "popup.html",
"src/options.html": "options.html",
"src/overlay.cs.js": "content-scripts/overlay.js",
}
})
]
}); |
First off, thank you so much @aklinker1 for this plugin -- it's been a lifesaver for me.
I have a question about configuring the url path names for internal extension pages (e.g. onboarding).
I have a page located at
src/pages/onboarding/index.html
that I would like to be accessible atchrome://<extension-id>/onboarding
.I've added the html path to my
vite.config.ts
like so:However, this makes the page's url
chrome://<extension-id>/src/pages/onboarding/index.html
. I'm not sure what other configuration is required in order to achieve what I'm looking for. Any help would be greatly appreciateed.The text was updated successfully, but these errors were encountered: