get it working
This commit is contained in:
Generated
+3
-3
@@ -4919,8 +4919,8 @@ packages:
|
||||
loose-envify: 1.4.0
|
||||
dev: false
|
||||
|
||||
/scule@1.0.0:
|
||||
resolution: {integrity: sha512-4AsO/FrViE/iDNEPaAQlb77tf0csuq27EsVpy6ett584EcRTp6pTDLoGWVxCD77y5iU5FauOvhsI4o1APwPoSQ==}
|
||||
/scule@1.3.0:
|
||||
resolution: {integrity: sha512-6FtHJEvt+pVMIB9IBY+IcCJ6Z5f1iQnytgyfKMhDKgmzYG+TeH/wx1y3l27rshSbLiSanrR9ffZDrEsmjlQF2g==}
|
||||
dev: false
|
||||
|
||||
/semver-diff@4.0.0:
|
||||
@@ -5550,7 +5550,7 @@ packages:
|
||||
mlly: 1.4.2
|
||||
pathe: 1.1.1
|
||||
pkg-types: 1.0.3
|
||||
scule: 1.0.0
|
||||
scule: 1.3.0
|
||||
strip-literal: 1.3.0
|
||||
unplugin: 1.5.0
|
||||
transitivePeerDependencies:
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
} from '~/core/utils/virtual-modules';
|
||||
import { Hookable } from 'hookable';
|
||||
import { toArray } from '~/core/utils/arrays';
|
||||
import { safeVarName } from '~/core/utils/strings';
|
||||
|
||||
export async function createViteBuilder(
|
||||
wxtConfig: ResolvedConfig,
|
||||
@@ -87,14 +88,22 @@ export async function createViteBuilder(
|
||||
plugins.push(wxtPlugins.cssEntrypoints(entrypoint, wxtConfig));
|
||||
}
|
||||
|
||||
const iifeReturnValueName = safeVarName(entrypoint.name);
|
||||
const libMode: vite.UserConfig = {
|
||||
mode: wxtConfig.mode,
|
||||
plugins,
|
||||
esbuild: {
|
||||
// Add a footer with the returned value so it can return values to `scripting.executeScript`
|
||||
// Footer is added apart of esbuild to make sure it's not minified. It
|
||||
// get's removed if added to `build.rollupOptions.output.footer`
|
||||
// See https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/scripting/executeScript#return_value
|
||||
footer: iifeReturnValueName + ';',
|
||||
},
|
||||
build: {
|
||||
lib: {
|
||||
entry,
|
||||
formats: ['iife'],
|
||||
name: '_',
|
||||
name: iifeReturnValueName,
|
||||
fileName: entrypoint.name,
|
||||
},
|
||||
rollupOptions: {
|
||||
|
||||
@@ -5,6 +5,14 @@ export function kebabCaseAlphanumeric(str: string): string {
|
||||
.replace(/\s+/g, '-'); // Replace spaces with hyphens
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a safe variable name for a given string.
|
||||
*/
|
||||
export function safeVarName(str: string): string {
|
||||
// _ prefix to ensure it doesn't start with a number
|
||||
return '_' + kebabCaseAlphanumeric(str).replace('-', '_');
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes import statements from the top of a file. Keeps import.meta and inline, async `import()`
|
||||
* calls.
|
||||
|
||||
@@ -17,7 +17,8 @@ const result = (async () => {
|
||||
}
|
||||
})();
|
||||
|
||||
// Return the main function's result to the background when executed via the scripting API.
|
||||
// Return the main function's result to the background when executed via the
|
||||
// scripting API. Default export causes the IIFE to return a value.
|
||||
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/scripting/executeScript#return_value
|
||||
// Tested on both Chrome and Firefox
|
||||
result;
|
||||
export default result;
|
||||
|
||||
@@ -14,7 +14,8 @@ const result = (async () => {
|
||||
}
|
||||
})();
|
||||
|
||||
// Return the main function's result to the background when executed via the scripting API.
|
||||
// Return the main function's result to the background when executed via the
|
||||
// scripting API. Default export causes the IIFE to return a value.
|
||||
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/scripting/executeScript#return_value
|
||||
// Tested on both Chrome and Firefox
|
||||
result;
|
||||
export default result;
|
||||
|
||||
@@ -13,7 +13,8 @@ const result = (async () => {
|
||||
}
|
||||
})();
|
||||
|
||||
// Return the main function's result to the background when executed via the scripting API.
|
||||
// Return the main function's result to the background when executed via the
|
||||
// scripting API. Default export causes the IIFE to return a value.
|
||||
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/scripting/executeScript#return_value
|
||||
// Tested on both Chrome and Firefox
|
||||
result;
|
||||
export default result;
|
||||
|
||||
Reference in New Issue
Block a user