Skip to content
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

Disable preload in Vite #8023

Closed
4 tasks done
ikangjie opened this issue May 5, 2022 · 3 comments
Closed
4 tasks done

Disable preload in Vite #8023

ikangjie opened this issue May 5, 2022 · 3 comments
Labels
invalid This doesn't seem right

Comments

@ikangjie
Copy link

ikangjie commented May 5, 2022

Clear and concise description of the problem

I now use "vite + vue3" to develop "Chrome ext", but now I encounter a very troublesome problem, that is, when I use the "import()" asynchronous function, "vite build" will add the fragment of import {} from "./preload-helper.js", but chrome ext does not support this. I consulted the official vite documentation and did not have this option to disable this preload, even if I used build Polyfillmodulepreload = false, still not effective. Can you have such an option to prohibit perload?

Suggested solution

build.preloads = false

Alternative

No response

Additional context

No response

Validations

@ikangjie
Copy link
Author

ikangjie commented May 5, 2022

dev:
./content.js
(async () => {
const src = chrome.runtime.getURL('uuidv4.js')
const uuidv4 = await import(src)
console.log(uuidv4.default())
})()

build:
./content.js
import {_} from "./preload-helper.js";
(async()=>{
const n = chrome.runtime.getURL("uuidv4.js")
, a = await _(()=>import(n), []);
console.log(a.default())
}
)();

chrome ext: Uncaught SyntaxError: Cannot use import statement outside a module

@sapphi-red
Copy link
Member

The problem here is that content script does not support esm. Vite bundles to esm by default.
You need to use lib.formats to output to iife like this.
https://github.com/antfu/vitesse-webext/blob/b676ddf825e0e977d2c5d561de7389db5371d646/vite.config.content.ts#L22
Also preload is disabled for lib mode so the problem won't appear if you switch to lib mode.

@sapphi-red
Copy link
Member

Closing as it is either invalid or a duplicate of #5991.

@sapphi-red sapphi-red added invalid This doesn't seem right and removed enhancement: pending triage labels May 5, 2022
@github-actions github-actions bot locked and limited conversation to collaborators May 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants