Compare commits

..

10 Commits

Author SHA1 Message Date
GitHub Actions f9a10c2c52 chore(release): wxt v0.18.7 2024-06-17 16:17:42 +00:00
Aaron 8206ca9164 fix(zip): Revert dotfile changes from #674 (#742) 2024-06-17 11:10:06 -05:00
Aaron 1a823cc008 chore: Extract build cache script to NPM package (#737) 2024-06-17 11:09:18 -05:00
Aaron efc011eb81 ci: Fix release 422 failure 2024-06-14 00:36:03 -05:00
GitHub Actions 35f6d28977 chore(release): @wxt-dev/module-solid v1.0.1 2024-06-14 05:29:40 +00:00
Aaron 43fcbec0eb fix: Add target: esnext by default (#733) 2024-06-14 00:25:11 -05:00
Aaron a0d56b4d27 chore: Update templates to use new modules (#732) 2024-06-14 00:19:13 -05:00
Aaron 38ccb6ace6 docs: Update frontend framework docs with new modules (#731) 2024-06-14 00:06:23 -05:00
Aaron aaf75f1de1 ci: Only mark wxt releases as latest 2024-06-14 00:02:41 -05:00
Aaron 21e8ca0a2c chore: Add changelog 2024-06-13 23:52:58 -05:00
29 changed files with 163 additions and 233 deletions
+1 -1
View File
@@ -18,7 +18,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- run: pnpm -r --sequential build
- run: pnpm buildc all
build-demo:
runs-on: ubuntu-22.04
steps:
+49 -29
View File
@@ -1,28 +1,59 @@
# Frontend Frameworks
WXT supports all frontend frameworks with a Vite plugin:
## Built-in Modules
- `@vitejs/plugin-vue`
- `@vitejs/plugin-react`
- `@vitejs/plugin-react-swc`
- And more!
WXT has preconfigured modules for 4 frameworks:
Just add the vite plugin to your config and you're good to go! Use the framework in HTML pages or content scripts, it will just work 👍
- [`@wxt-dev/module-react`](https://github.com/wxt-dev/wxt/tree/main/packages/module-react)
- [`@wxt-dev/module-vue`](https://github.com/wxt-dev/wxt/tree/main/packages/module-vue)
- [`@wxt-dev/module-svelte`](https://github.com/wxt-dev/wxt/tree/main/packages/module-svelte)
- [`@wxt-dev/module-solid`](https://github.com/wxt-dev/wxt/tree/main/packages/module-solid)
Install the module for your framework, then add it to your config:
:::code-group
```ts [Vue]
```ts [React]
import { defineConfig } from 'wxt';
import vue from '@vitejs/plugin-vue';
export default defineConfig({
vite: () => ({
plugins: [vue()],
}),
modules: ['@wxt-dev/module-react'],
});
```
```ts [React]
```ts [Vue]
import { defineConfig } from 'wxt';
export default defineConfig({
modules: ['@wxt-dev/module-vue'],
});
```
```ts [Svelte]
import { defineConfig } from 'wxt';
export default defineConfig({
modules: ['@wxt-dev/module-svelte'],
});
```
```ts [Solid]
import { defineConfig } from 'wxt';
export default defineConfig({
modules: ['@wxt-dev/module-solid'],
});
```
:::
## Adding Vite Plugins
If your framework doesn't have an official WXT module, no worries! WXT supports any framework with a Vite plugin.
Just add the Vite plugin to your config and you're good to go! Use the framework in HTML pages or content scripts, it will just work 👍
```ts
import { defineConfig } from 'wxt';
import react from '@vitejs/plugin-react';
@@ -33,18 +64,7 @@ export default defineConfig({
});
```
```ts [Svelte]
import { defineConfig } from 'wxt';
import { svelte } from '@sveltejs/vite-plugin-svelte';
export default defineConfig({
vite: () => ({
plugins: [svelte()],
}),
});
```
:::
The WXT modules just simplify the configuration and add auto-imports. They're not much different than the above.
## Multiple Apps
@@ -84,9 +104,9 @@ Lots of frameworks come with routers for building a multi-page app using the URL
Instead, you need to configure the router to run in "hash" mode, where the routing information is apart of the URL's hash, not the path (ie: `popup.html#/` and `popup.html#/account/settings`)
Refer to your router's docs for information about "hash" mode and how to enable it. Here's a non-extensive list of a few popular routers:
Refer to your router's docs for information about hash mode and how to enable it. Here's a non-extensive list of a few popular routers:
- [React](https://reactrouter.com/en/main/routers/create-hash-router)
- [Vue](https://router.vuejs.org/guide/essentials/history-mode.html#Hash-Mode)
- [Svelte](https://www.npmjs.com/package/svelte-spa-router#hash-based-routing)
- [Solid](https://github.com/solidjs/solid-router?tab=readme-ov-file#hash-mode-router)
- [`react-router`](https://reactrouter.com/en/main/routers/create-hash-router)
- [`vue-router`](https://router.vuejs.org/guide/essentials/history-mode.html#Hash-Mode)
- [`svelte-spa-router`](https://www.npmjs.com/package/svelte-spa-router#hash-based-routing)
- [`solid-router`](https://github.com/solidjs/solid-router?tab=readme-ov-file#hash-mode-router)
+2 -2
View File
@@ -15,10 +15,10 @@
"docs:gen": "typedoc --options docs/typedoc.json",
"docs:dev": "pnpm -s docs:gen && vitepress dev docs",
"docs:build": "pnpm -s docs:gen && vitepress build docs",
"docs:preview": "pnpm -s docs:gen && vitepress preview docs",
"build-deps": "pnpm tsx scripts/build-deps.ts"
"docs:preview": "pnpm -s docs:gen && vitepress preview docs"
},
"devDependencies": {
"@aklinker1/buildc": "^1.0.5",
"@aklinker1/check": "^1.3.1",
"@types/fs-extra": "^11.0.4",
"@vitest/coverage-v8": "^1.6.0",
+5
View File
@@ -0,0 +1,5 @@
# Changelog
## v1.0.0
Initial release 🎉
+2 -3
View File
@@ -21,9 +21,8 @@
"dist"
],
"scripts": {
"build": "pnpm -s build-deps && unbuild",
"check": "pnpm -s build-deps && check",
"build-deps": "pnpm -ws build-deps @wxt-dev/module-react"
"build": "buildc -- unbuild",
"check": "buildc --deps-only -- check"
},
"peerDependencies": {
"wxt": ">=0.18.5"
+17
View File
@@ -0,0 +1,17 @@
# Changelog
## v1.0.1
[compare changes](https://github.com/wxt-dev/wxt/compare/module-solid-v1.0.0...module-solid-v1.0.1)
### 🩹 Fixes
- Add `target: esnext` by default ([#733](https://github.com/wxt-dev/wxt/pull/733))
### 🏡 Chore
- Add changelog ([21e8ca0](https://github.com/wxt-dev/wxt/commit/21e8ca0))
## v1.0.0
Initial release 🎉
+1 -1
View File
@@ -4,7 +4,7 @@ Enables the use of [SolidJS](https://www.solidjs.com/) in your web extension, in
This plugin makes a few changes:
1. Adds `vite-plugin-solid` to vite
1. Adds `vite-plugin-solid` to and sets `build.target: esnext` in the vite config
2. Adds the [`solid-js` preset](https://github.com/unjs/unimport/blob/main/src/presets/solid.ts) to auto-imports
## Usage
+3 -4
View File
@@ -1,6 +1,6 @@
{
"name": "@wxt-dev/module-solid",
"version": "1.0.0",
"version": "1.0.1",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
@@ -21,9 +21,8 @@
"dist"
],
"scripts": {
"build": "pnpm -s build-deps && unbuild",
"check": "pnpm -s build-deps && check",
"build-deps": "pnpm -ws build-deps @wxt-dev/module-solid"
"build": "buildc -- unbuild",
"check": "buildc --deps-only -- check"
},
"peerDependencies": {
"wxt": ">=0.18.5"
+3
View File
@@ -10,6 +10,9 @@ export default defineWxtModule<SolidModuleOptions>({
addViteConfig(wxt, () => ({
plugins: [solid(vite)],
build: {
target: 'esnext',
},
}));
addImportPreset(wxt, 'solid-js');
+5
View File
@@ -0,0 +1,5 @@
# Changelog
## v1.0.0
Initial release 🎉
+2 -3
View File
@@ -21,9 +21,8 @@
"dist"
],
"scripts": {
"build": "pnpm -s build-deps && unbuild",
"check": "pnpm -s build-deps && check",
"build-deps": "pnpm -ws build-deps @wxt-dev/module-svelte"
"build": "buildc -- unbuild",
"check": "buildc --deps-only -- check"
},
"peerDependencies": {
"wxt": ">=0.18.5"
+5
View File
@@ -0,0 +1,5 @@
# Changelog
## v1.0.0
Initial release 🎉
+2 -3
View File
@@ -21,9 +21,8 @@
"dist"
],
"scripts": {
"build": "pnpm -s build-deps && unbuild",
"check": "pnpm -s build-deps && check",
"build-deps": "pnpm -ws build-deps @wxt-dev/module-vue"
"build": "buildc -- unbuild",
"check": "buildc --deps-only -- check"
},
"peerDependencies": {
"wxt": ">=0.18.5"
+10 -8
View File
@@ -4,18 +4,17 @@
"private": true,
"type": "module",
"scripts": {
"dev": "pnpm -s build-deps && wxt",
"build": "pnpm -s build-deps && wxt build",
"build:all": "pnpm -s build-deps && run-s -s 'build:all:*'",
"dev": "buildc -- wxt",
"build": "buildc --deps-only -- wxt build",
"build:all": "buildc --deps-only -- run-s -s 'build:all:*'",
"build:all:chrome-mv3": "wxt build",
"build:all:chrome-mv2": "wxt build --mv2",
"build:all:firefox-mv3": "wxt build -b firefox --mv3",
"build:all:firefox-mv2": "wxt build -b firefox",
"test": "pnpm -s build-deps && vitest",
"zip": "pnpm -s build-deps && wxt zip",
"check": "pnpm -s build-deps && check",
"postinstall": "pnpm -s build-deps && wxt prepare",
"build-deps": "pnpm -sw build-deps wxt-demo"
"test": "buildc --deps-only -- vitest",
"zip": "buildc --deps-only -- wxt zip",
"check": "buildc --deps-only -- check",
"postinstall": "buildc --deps-only -- wxt prepare"
},
"dependencies": {
"react": "^18.3.1",
@@ -27,5 +26,8 @@
"sass": "^1.77.5",
"typescript": "^5.4.5",
"wxt": "workspace:*"
},
"buildc": {
"outDir": ".output/chrome-mv3"
}
}
+15
View File
@@ -1,5 +1,20 @@
# Changelog
## v0.18.7
[compare changes](https://github.com/wxt-dev/wxt/compare/wxt-v0.18.6...wxt-v0.18.7)
### 🩹 Fixes
- **dev:** Fix CSP error loading HTML plugins ([#723](https://github.com/wxt-dev/wxt/pull/723))
- Generalize react-refresh preamble logic to virtualize all inline scripts ([#728](https://github.com/wxt-dev/wxt/pull/728))
- **zip:** Revert dotfile changes from #674 ([#742](https://github.com/wxt-dev/wxt/pull/742), [#674](https://github.com/wxt-dev/wxt/issues/674))
### 🏡 Chore
- **deps:** Upgrade and sync all dependencies ([#725](https://github.com/wxt-dev/wxt/pull/725))
- Extract build cache script to NPM package ([#737](https://github.com/wxt-dev/wxt/pull/737))
## v0.18.6
[compare changes](https://github.com/wxt-dev/wxt/compare/wxt-v0.18.5...wxt-v0.18.6)
+4 -2
View File
@@ -97,7 +97,8 @@ describe('Zipping', () => {
expect(await project.fileExists(sourcesZip)).toBe(true);
});
it('should not zip hidden files into sources by default', async () => {
// TODO: Fix #738 and re-enable
it.skip('should not zip hidden files into sources by default', async () => {
const project = new TestProject({
name: 'test',
version: '1.0.0',
@@ -117,7 +118,8 @@ describe('Zipping', () => {
expect(await project.fileExists(unzipDir, '.env')).toBe(false);
});
it('should allow zipping hidden files into sources when explicitly listed', async () => {
// TODO: Fix #738 and re-enable
it.skip('should allow zipping hidden files into sources when explicitly listed', async () => {
const project = new TestProject({
name: 'test',
version: '1.0.0',
+5 -5
View File
@@ -1,7 +1,7 @@
{
"name": "wxt",
"type": "module",
"version": "0.18.6",
"version": "0.18.7",
"description": "Next gen framework for developing web extensions",
"repository": {
"type": "git",
@@ -92,12 +92,12 @@
},
"scripts": {
"wxt": "tsx src/cli/index.ts",
"build": "tsx scripts/build.ts",
"check": "run-s -c check:*",
"build": "buildc -- tsx scripts/build.ts",
"check": "buildc --deps-only -- run-s -c check:*",
"check:default": "check",
"check:tsc-virtual": "tsc --noEmit -p src/virtual",
"test": "vitest",
"test:e2e": "vitest -r e2e",
"test": "buildc --deps-only -- vitest",
"test:e2e": "buildc --deps-only -- vitest -r e2e",
"sync-releases": "pnpx changelogen@latest gh release"
},
"dependencies": {
+2 -1
View File
@@ -104,7 +104,8 @@ async function zipDir(
// Ignore node_modules, otherwise this glob step takes forever
ignore: ['**/node_modules'],
onlyFiles: true,
dot: true,
// TODO: Fix #738
// dot: true,
})
).filter((relativePath) => {
return (
+20
View File
@@ -8,6 +8,9 @@ importers:
.:
devDependencies:
'@aklinker1/buildc':
specifier: ^1.0.5
version: 1.0.5(typescript@5.4.5)
'@aklinker1/check':
specifier: ^1.3.1
version: 1.3.1(typescript@5.4.5)
@@ -374,6 +377,23 @@ importers:
packages:
/@aklinker1/buildc@1.0.5(typescript@5.4.5):
resolution: {integrity: sha512-xM9tA6VpkHh2qTCVBwuXUGdBpgxtnj35zrDT0hMBWBLAoAvNXjQrGf4DaFN+gnBsd32TtFPDg1IfcW2ZcUF0ZQ==}
hasBin: true
peerDependencies:
typescript: ^5.0.0
dependencies:
cac: 6.7.14
consola: 3.2.3
dependency-graph: 1.0.0
fast-glob: 3.3.2
fs-extra: 11.2.0
ohash: 1.1.3
pathe: 1.1.2
typescript: 5.4.5
yaml: 2.4.5
dev: true
/@aklinker1/check@1.3.1(typescript@5.4.5):
resolution: {integrity: sha512-EALKJzoojytjC6cYLIjRjC+nNpVdqSWYjJm8FTUtWneemKDs+Q46PaMyEx2EYTRbj4fO0OXj9igABwbpp/vV4g==}
hasBin: true
-133
View File
@@ -1,133 +0,0 @@
//
// Build all workspace packages, or only dependencies of a specific package.
// Kind of a simple version of nx/turborepo, but we can keep using PNPM to run
// all commands.
//
// Usage:
// pnpm tsx scripts/build-deps.ts # Builds all packages in repo
// pnpm tsx scripts/build-deps.ts <packageName> # Builds only dependencies of <packageName>
//
import glob from 'fast-glob';
import { DepGraph } from 'dependency-graph';
import fs from 'fs-extra';
import YAML from 'yaml';
import { execa } from 'execa';
import consola from 'consola';
import { hashFile, hash } from 'hasha';
import { resolve } from 'node:path';
// Quick hack to prevent recursive calls to this script. If it's being called
// from another instance of this script, the parent instance is already
// preforming this build, so it can be skipped.
if (process.env.BUILD_DEPS) process.exit(0);
process.env.BUILD_DEPS = 'true';
// Parse args
const packageToBuild = process.argv[2];
if (packageToBuild == null) {
consola.info('Building all packages...');
} else {
consola.info(`Building dependencies of \`${packageToBuild}\``);
}
// Build graph
const workspace: { packages: string[] } = YAML.parse(
await fs.readFile('pnpm-workspace.yaml', 'utf8'),
);
const packageDirs = await glob(workspace.packages, { onlyDirectories: true });
const graph = new DepGraph<Record<string, any>>();
// Add all packages to chart
for (const packageDir of packageDirs) {
try {
const packageJson = await fs.readJson(`${packageDir}/package.json`);
graph.addNode(packageJson.name, { ...packageJson, dir: packageDir });
} catch {
// Package missing package.json, ignore it
}
}
// Add dependencies between packages
graph.entryNodes().forEach((packageName) => {
const packageJson = graph.getNodeData(packageName);
[
...Object.entries<string>(packageJson.dependencies ?? {}),
...Object.entries<string>(packageJson.devDependencies ?? {}),
].forEach(([dep, version]) => {
if (version !== 'workspace:*') return;
graph.addDependency(packageName, dep);
});
});
function printGraph(graph: DepGraph<any>) {
consola.debug('Dependency Graph:');
function printNode(node: string, level = 0) {
consola.debug(`${''.padStart(level * 2, ' ')}- \`${node}\``);
graph.dependenciesOf(node).forEach((dep) => printNode(dep, level + 1));
}
graph.entryNodes().forEach((entry) => printNode(entry));
}
printGraph(graph);
if (packageToBuild) {
// Remove nodes not associated with the package to build
graph.entryNodes().forEach((entry) => {
if (entry !== packageToBuild) graph.removeNode(entry);
});
}
// Get order
const buildOrder = graph.overallOrder().filter(
// Remove packageToBuild if provided
(packageName) => packageName !== packageToBuild,
);
consola.info('Build order:', buildOrder);
// Build dependencies of a package
async function hashDir(dir: string): Promise<string> {
const files = await glob('**/*', {
ignore: [
'**/dist/**',
'**/node_modules/**',
'**/__tests__/**',
'**/e2e/**',
'CHANGELOG.md',
'typedoc.json',
'vitest.*.ts',
],
cwd: dir,
});
const hashes = await Promise.all(
files.sort().map(async (file) => {
const hash = await hashFile(resolve(dir, file), { algorithm: 'md5' });
return `${hash}-${file}`;
}),
);
consola.debug(hashes.join('\n'));
return await hash(hashes.join('\n'), { algorithm: 'md5' });
}
async function buildPackage(packageName: string): Promise<void> {
const packageJson = graph.getNodeData(packageName);
const hash = await hashDir(packageJson.dir);
consola.debug('Directory hash:', hash);
const cacheDir = resolve('.cache', packageJson.dir, hash);
const outputDir = resolve(packageJson.dir, 'dist');
if (await fs.pathExists(cacheDir)) {
await fs.ensureDir(outputDir);
await fs.copy(cacheDir, outputDir);
consola.success(`\`${packageName}\` cached`);
} else {
await execa('pnpm', ['--filter', packageName, 'build'], {
stdio: 'inherit',
});
await fs.ensureDir(cacheDir);
await fs.copy(outputDir, cacheDir);
}
}
try {
for (const packageName of buildOrder) {
await buildPackage(packageName);
}
} catch (err) {
consola.error(err);
process.exit(1);
}
+2
View File
@@ -29,5 +29,7 @@ await createGithubRelease(config, {
tag_name: prevTag,
name: `${pkgName} v${currentVersion}`,
body: releases[0].body,
// @ts-expect-error: Not typed in changelogen, but present: https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#create-a-release
make_latest: String(pkg === 'wxt'),
});
consola.success('Created release');
+1 -1
View File
@@ -21,7 +21,7 @@
"devDependencies": {
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.1",
"@wxt-dev/module-react": "^1.0.0",
"typescript": "^5.4.5",
"wxt": "^0.18.6"
}
+1 -4
View File
@@ -1,9 +1,6 @@
import { defineConfig } from 'wxt';
import react from '@vitejs/plugin-react';
// See https://wxt.dev/api/config.html
export default defineConfig({
vite: () => ({
plugins: [react()],
}),
modules: ['@wxt-dev/module-react'],
});
+1 -1
View File
@@ -19,7 +19,7 @@
},
"devDependencies": {
"typescript": "^5.4.5",
"vite-plugin-solid": "^2.10.2",
"@wxt-dev/module-solid": "^1.0.0",
"wxt": "^0.18.6"
}
}
+1 -7
View File
@@ -1,12 +1,6 @@
import { defineConfig } from 'wxt';
import Solid from 'vite-plugin-solid';
// See https://wxt.dev/api/config.html
export default defineConfig({
vite: () => ({
build: {
target: 'esnext',
},
plugins: [Solid()],
}),
modules: ['@wxt-dev/module-solid'],
});
+1 -1
View File
@@ -14,8 +14,8 @@
"postinstall": "wxt prepare"
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^3.1.1",
"@tsconfig/svelte": "^5.0.4",
"@wxt-dev/module-svelte": "^1.0.0",
"svelte": "^4.2.18",
"svelte-check": "^3.8.0",
"tslib": "^2.6.3",
+1 -10
View File
@@ -1,16 +1,7 @@
import { defineConfig } from 'wxt';
import { svelte, vitePreprocess } from '@sveltejs/vite-plugin-svelte';
// See https://wxt.dev/api/config.html
export default defineConfig({
srcDir: 'src',
vite: () => ({
plugins: [
svelte({
// Using a svelte.config.js file causes a segmentation fault when importing the file
configFile: false,
preprocess: [vitePreprocess()],
}),
],
}),
modules: ['@wxt-dev/module-svelte'],
});
+1 -1
View File
@@ -18,7 +18,7 @@
"vue": "^3.4.27"
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.0.5",
"@wxt-dev/module-vue": "^1.0.0",
"typescript": "^5.4.5",
"vue-tsc": "^2.0.21",
"wxt": "^0.18.6"
+1 -13
View File
@@ -1,18 +1,6 @@
import { defineConfig } from 'wxt';
import vue from '@vitejs/plugin-vue';
// See https://wxt.dev/api/config.html
export default defineConfig({
imports: {
addons: {
vueTemplate: true,
},
},
vite: () => ({
plugins: [vue()],
build: {
// Enabling sourcemaps with Vue during development is known to cause problems with Vue
sourcemap: false,
},
}),
modules: ['@wxt-dev/module-vue'],
});