-
-
Notifications
You must be signed in to change notification settings - Fork 395
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
Multiple content pages not support #177
Comments
Thank you for your contribution. We will check and reply to you as soon as possible. |
The current manifest configuration can only support one content script, but let's make it better! You can modify your own build settings and manifest settings to load more than one content script. I'll try to make it easier to do this in Boilerplate, but I don't think it's a high priority. |
yeah,after several attempts, I solved this problem using a // utils/plugins/inline-vite-preload.ts
export default function inlineVitePreloadScript() {
let __vitePreload = '';
return {
name: 'replace-vite-preload-script-plugin',
async renderChunk(code, chunk, options, meta) {
if (!/content/.test(chunk.fileName)) {
return null;
}
if (!__vitePreload) {
const chunkName = Object.keys(meta.chunks).find(key => /preload/.test(key));
const modules = meta.chunks[chunkName].modules;
__vitePreload = modules[Object.keys(modules)[0]].code;
}
return {
code: __vitePreload + code.split(`\n`).slice(1).join(`\n`),
};
},
};
} // vite.config.ts
import inlineVitePreloadScript from './utils/plugins/inline-vite-preload';
...,
plugins:[
...
inlineVitePreloadScript()
] |
@Jonghakseo appreciate all the work on the boilerplate, it's been really helpful to use. FWIW, I also need to support multiple content scripts as the extension I'm building has different functionality by domain and I'm trying to keep the permissions as minimal as possible to start and the code modular. Adding a heads up/pointer to this issue in the README may be helpful a short-term solution. @rosendolu Thanks for posting the fix! |
@rosendolu this still works like a charm. Thanks! |
@all-contributors please add @rosendolu for code |
I've put up a pull request to add @rosendolu! 🎉 |
Ported from: Jonghakseo/chrome-extension-boilerplate-react-vite@e56fa10 as per: Jonghakseo/chrome-extension-boilerplate-react-vite#177 (comment) We don't need this right now, but it's handy to keep in the back pocket, and also minimise divergence from Jonghakseo/chrome-extension-boilerplate-react-vite.
Ported from: Jonghakseo/chrome-extension-boilerplate-react-vite@e56fa10 as per: Jonghakseo/chrome-extension-boilerplate-react-vite#177 (comment) We don't need this right now, but it's handy to keep in the back pocket, and also minimise divergence from Jonghakseo/chrome-extension-boilerplate-react-vite.
Describe the bug
To Reproduce
Steps to reproduce the behavior:
npm run build
Expected behavior
Works normally
Screenshots
Desktop (please complete the following information):
Additional context
When only one content pages, after build ,it works well ,and without any
import script
But when multiple content pages added ,the
__vitePreload
script came to be imported usingimport
,and browser not allowed that.I think it might be the rollups default behavior,but did`t found a way outThe text was updated successfully, but these errors were encountered: