-
-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
115 additions
and
2 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
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
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
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* Utilities for creating reusable, build-time modules for WXT. | ||
* | ||
* @module wxt/modules | ||
*/ | ||
import type { | ||
Entrypoint, | ||
EntrypointGroup, | ||
ResolvedConfig, | ||
Wxt, | ||
WxtModule, | ||
WxtModuleOptions, | ||
} from './types'; | ||
import * as vite from 'vite'; | ||
|
||
export function defineWxtModule<TOptions extends WxtModuleOptions>( | ||
module: WxtModule<TOptions> | WxtModule<TOptions>['setup'], | ||
): WxtModule<TOptions> { | ||
if (typeof module === 'function') return { setup: module }; | ||
return module; | ||
} | ||
|
||
/** | ||
* Adds a TS/JS file as an entrypoint to the project. | ||
* | ||
* @argument wxt The wxt instance provided by the module's setup function. | ||
* @argument entrypoint The entrypoint to be bundled along with the extension. | ||
* | ||
* @example | ||
* export default defineWxtPlugin({ | ||
* setup(wxt) { | ||
* addEntrypoint(wxt, { | ||
* type: "unlisted-page", | ||
* name: "changelog", | ||
* inputPath: "wxt-module-changelog/index.html" | ||
* outputDir: wxt.config.outputDir, | ||
* options: {}, | ||
* }); | ||
* } | ||
* }); | ||
*/ | ||
export function addEntrypoint(wxt: Wxt, entrypoint: Entrypoint): void { | ||
throw Error('TODO'); | ||
} | ||
|
||
/** | ||
* Merge additional vite config for one or more entrypoint "groups" that make | ||
* up individual builds. | ||
* | ||
* @argument wxt The wxt instance provided by the module's setup function. | ||
* @argument viteConfig A callback function taking the entrypoints that will be | ||
* built as the first argument and returns additional Vite | ||
* config that will be merged into the config used to | ||
* bundle the entrypoint group. | ||
* | ||
* @example | ||
* export default defineWxtPlugin({ | ||
* setup(wxt) { | ||
* mergeViteConfig(wxt, (group) => ({ | ||
* build: { | ||
* sourceMaps: true, | ||
* }, | ||
* }); | ||
* } | ||
* }); | ||
*/ | ||
export function mergeViteConfig( | ||
wxt: Wxt, | ||
viteConfig: (group: EntrypointGroup) => vite.UserConfig | undefined, | ||
): void { | ||
throw Error('TODO'); | ||
} | ||
|
||
/** | ||
* Add JS code to a JS entrypoint. | ||
* | ||
* @argument wxt The wxt instance provided by the module's setup function. | ||
* @argument js Code that will be added to the entrypoint. Includes any top-level imports to add, | ||
*/ | ||
export function addJs() { | ||
throw Error('TODO'); | ||
} |
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
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
"src/sandbox/index.ts", | ||
"src/browser.ts", | ||
"src/index.ts", | ||
"src/storage.ts" | ||
"src/storage.ts", | ||
"src/modules.ts" | ||
] | ||
} |