-
-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Aaron <[email protected]>
- Loading branch information
Showing
15 changed files
with
703 additions
and
11 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 |
---|---|---|
|
@@ -13,6 +13,7 @@ on: | |
- module-solid | ||
- module-svelte | ||
- module-vue | ||
- unocss | ||
- wxt | ||
|
||
jobs: | ||
|
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 @@ | ||
<!--@include: ../packages/unocss/README.md--> |
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,47 @@ | ||
# WXT UnoCSS | ||
|
||
Use UnoCSS in your WXT extension! | ||
|
||
## Usage | ||
|
||
Install the package: | ||
|
||
```sh | ||
npm i --save-dev @wxt-dev/unocss unocss | ||
pnpm i -D @wxt-dev/unocss unocss | ||
yarn add --dev @wxt-dev/unocss unocss | ||
bun i -D @wxt-dev/unocss unocss | ||
``` | ||
|
||
Add the module to `wxt.config.ts`: | ||
|
||
```ts | ||
export default defineConfig({ | ||
modules: ['@wxt-dev/unocss'], | ||
}); | ||
``` | ||
|
||
Now in your entrypoint, import UnoCSS: | ||
|
||
```ts | ||
import 'uno.css'; | ||
``` | ||
|
||
> [!IMPORTANT] | ||
> While in dev mode, you may see a warning about `uno.css` not being found. This is because in development, we don't know which files should be injected with UnoCSS styles. The warning can be safely ignored as the styles will be properly applied during the build process. | ||
## Configuration | ||
|
||
The module can be configured via the `unocss` config: | ||
|
||
```ts | ||
export default defineConfig({ | ||
modules: ['@wxt-dev/unocss'], | ||
unocss: { | ||
// Will only apply unocss for popup/main.ts | ||
entrypoints: ['popup/main.ts'], | ||
}, | ||
}); | ||
``` | ||
|
||
Options have JSDocs available in your editor, or you can read them in the source code: [`UnoCSSOptions`](./src/index.ts). |
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,55 @@ | ||
{ | ||
"name": "@wxt-dev/unocss", | ||
"description": "UnoCSS integration for WXT", | ||
"version": "1.0.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/wxt-dev/wxt.git", | ||
"directory": "packages/unocss" | ||
}, | ||
"homepage": "http://wxt.dev/guide/unocss.html", | ||
"keywords": [ | ||
"wxt", | ||
"module", | ||
"unocss", | ||
"css" | ||
], | ||
"author": { | ||
"name": "Florian Metz", | ||
"email": "[email protected]" | ||
}, | ||
"license": "MIT", | ||
"type": "module", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.mts", | ||
"default": "./dist/index.mjs" | ||
} | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "buildc -- unbuild", | ||
"check": "buildc --deps-only -- check" | ||
}, | ||
"peerDependencies": { | ||
"unocss": ">=0.60.0", | ||
"wxt": ">=0.19.0" | ||
}, | ||
"devDependencies": { | ||
"@aklinker1/check": "^1.4.5", | ||
"oxlint": "^0.9.9", | ||
"publint": "^0.2.11", | ||
"typescript": "^5.6.2", | ||
"unbuild": "^2.0.0", | ||
"unocss": "^0.63.3", | ||
"wxt": "workspace:*" | ||
}, | ||
"dependencies": { | ||
"defu": "^6.1.4", | ||
"fast-glob": "^3.3.2" | ||
} | ||
} |
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,68 @@ | ||
import 'wxt'; | ||
import { defineWxtModule } from 'wxt/modules'; | ||
import defu from 'defu'; | ||
import UnoCSS from 'unocss/vite'; | ||
|
||
export default defineWxtModule<UnoCSSOptions>({ | ||
name: '@wxt-dev/unocss', | ||
configKey: 'unocss', | ||
async setup(wxt, options) { | ||
const resolvedOptions = defu<Required<UnoCSSOptions>, UnoCSSOptions[]>( | ||
options, | ||
{ | ||
enabled: true, | ||
excludeEntrypoints: ['background'], | ||
configOrPath: undefined, | ||
}, | ||
); | ||
|
||
if (!resolvedOptions.enabled) | ||
return wxt.logger.warn(`\`[unocss]\` ${this.name} disabled`); | ||
|
||
const excludedEntrypoints = new Set(resolvedOptions.excludeEntrypoints); | ||
if (wxt.config.debug) { | ||
wxt.logger.debug( | ||
`\`[unocss]\` Excluded entrypoints:`, | ||
[...excludedEntrypoints].join(', '), | ||
); | ||
} | ||
|
||
wxt.hooks.hook('vite:devServer:extendConfig', (config) => { | ||
config.plugins?.push(UnoCSS()); | ||
}); | ||
|
||
wxt.hooks.hook('vite:build:extendConfig', async (entries, config) => { | ||
if (entries.every((entry) => excludedEntrypoints.has(entry.name))) return; | ||
config.plugins?.push(UnoCSS(resolvedOptions.configOrPath)); | ||
}); | ||
}, | ||
}); | ||
|
||
/** | ||
* Options for the UnoCSS module | ||
*/ | ||
export interface UnoCSSOptions<Theme extends object = object> { | ||
/** | ||
* Enable UnoCSS | ||
* @default true | ||
*/ | ||
enabled?: boolean; | ||
/** | ||
* List of entrypoint names that UnoCSS is not used in. By default, the UnoCSS | ||
* vite plugin is added to all build steps, but this option is used to exclude | ||
* it from specific builds. | ||
* @example ["popup", "options"] | ||
* @default [] | ||
*/ | ||
excludeEntrypoints?: string[]; | ||
/** | ||
* The path to your `unocss.config.ts` file, relative to <rootDir>, or inline configuration. | ||
*/ | ||
configOrPath?: Parameters<typeof UnoCSS<Theme>>[0]; | ||
} | ||
|
||
declare module 'wxt' { | ||
export interface InlineConfig { | ||
unocss?: UnoCSSOptions; | ||
} | ||
} |
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,4 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"exclude": ["node_modules/**", "dist/**"] | ||
} |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,11 +1,6 @@ | ||
:root { | ||
color-scheme: dark; | ||
color: indianred; | ||
} | ||
html { | ||
background-color: black; | ||
} | ||
|
||
div { | ||
padding: 16px; | ||
} |
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 @@ | ||
export { default } from '@wxt-dev/unocss'; |
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
Oops, something went wrong.