-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: import.meta.glob problem on vite >= 4.4.8
vitejs/vite#13973 - above fix makes import.meta.glob to ignore 'modulePreload: false' option. so, css are preloaded by wrapper function and occurs error because wrapper function does not use chrome.runtime.getURL for css files. - so, prevented dynamic import from being wrapped by vite preloader.
- Loading branch information
Showing
1 changed file
with
29 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,47 @@ | ||
import { ScriptIds } from 'src/constants/scripts'; | ||
import { SCRIPT_IDS } from 'src/messaging'; | ||
import messaging from './messaging'; | ||
import './routes'; | ||
import './stores'; | ||
import { initI18next } from "src/i18n"; | ||
import { createLanguageDetector } from "src/i18n/languageDetectors/twitch"; | ||
import { waitForDOMReady } from 'src/util/waitForDOMReady'; | ||
|
||
|
||
(async() => { | ||
await messaging.waitForConnected(SCRIPT_IDS.CONTENT); | ||
|
||
messaging.postMessage({ type: "GET_LANGUAGE" }); | ||
const browserUILang = await messaging.waitForMessage<string>(ScriptIds.CONTENT, "LANGUAGE"); | ||
const browserUILang = await messaging.waitForMessage<string>(SCRIPT_IDS.CONTENT, "LANGUAGE"); | ||
|
||
/** initialize i18next */ | ||
const languageDetector = createLanguageDetector(browserUILang); | ||
initI18next(languageDetector); | ||
initI18next({ languageDetector }); | ||
|
||
/** load modules */ | ||
const modules = import.meta.glob('./modules/*/index.ts'); | ||
|
||
await waitForDOMReady(); | ||
|
||
Object.keys(modules).forEach(path => modules[path]()); | ||
if (import.meta.env.DEV) { | ||
const modules = import.meta.glob('./modules/*/index.ts'); | ||
Object.values(modules).forEach(module => module()); | ||
} else { | ||
// to prevent dynamic import from being wrapped by vite preloader | ||
const modulePaths = import.meta.glob('./modules/*/index.ts', { | ||
query: { script: true, module: true }, | ||
import: 'default', | ||
eager: true | ||
}); | ||
|
||
Object.values(modulePaths) | ||
.forEach(path => { | ||
try { | ||
if (typeof path !== 'string') { | ||
throw new Error('module path is not string'); | ||
} | ||
import(/* @vite-ignore */ path); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
}); | ||
} | ||
|
||
})(); |