diff --git a/demo/entrypoints/background.ts b/demo/entrypoints/background.ts new file mode 100644 index 000000000..37774960f --- /dev/null +++ b/demo/entrypoints/background.ts @@ -0,0 +1,6 @@ +import { defineBackgroundScript } from 'exvite/client'; +import browser from 'webextension-polyfill'; + +export default defineBackgroundScript(() => { + console.log(browser.runtime.id); +}); diff --git a/demo/entrypoints/options/index.html b/demo/entrypoints/options/index.html new file mode 100644 index 000000000..0a57a3027 --- /dev/null +++ b/demo/entrypoints/options/index.html @@ -0,0 +1,13 @@ + + +
+ + +Hello options page!
+ + + diff --git a/demo/entrypoints/options/main.ts b/demo/entrypoints/options/main.ts new file mode 100644 index 000000000..6dd6c10ed --- /dev/null +++ b/demo/entrypoints/options/main.ts @@ -0,0 +1,3 @@ +import browser from 'webextension-polyfill'; + +console.log(browser.runtime.id); diff --git a/demo/entrypoints/options/style.css b/demo/entrypoints/options/style.css new file mode 100644 index 000000000..f129d8613 --- /dev/null +++ b/demo/entrypoints/options/style.css @@ -0,0 +1,4 @@ +html { + background: black; + color: white; +} diff --git a/demo/entrypoints/overlay.content.ts b/demo/entrypoints/overlay.content.ts new file mode 100644 index 000000000..a5891d434 --- /dev/null +++ b/demo/entrypoints/overlay.content.ts @@ -0,0 +1,11 @@ +import { defineContentScript, mountContentScriptUi } from 'exvite/client'; +import browser from 'webextension-polyfill'; + +export default defineContentScript({ + matches: ['*://*/*'], + async main() { + console.log(browser.runtime.id); + + mountContentScriptUi(); + }, +}); diff --git a/demo/entrypoints/popup.html b/demo/entrypoints/popup.html new file mode 100644 index 000000000..53cb0387e --- /dev/null +++ b/demo/entrypoints/popup.html @@ -0,0 +1,11 @@ + + + + + +Hello popup!
+ + diff --git a/demo/package.json b/demo/package.json index 9f4d62604..163d83f98 100644 --- a/demo/package.json +++ b/demo/package.json @@ -5,10 +5,11 @@ "build": "pnpm -w build && exvite build", "prepare": "pnpm -w build && exvite prepare" }, + "dependencies": { + "webextension-polyfill": "^0.10.0" + }, "devDependencies": { + "@types/webextension-polyfill": "^0.10.0", "exvite": "workspace:*" - }, - "dependencies": { - "unimport": "^3.0.8" } } diff --git a/demo/tsconfig.json b/demo/tsconfig.json new file mode 100644 index 000000000..cf8118394 --- /dev/null +++ b/demo/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../tsconfig.base.json", + "exclude": [".output"] +} diff --git a/demo/utils/logger.ts b/demo/utils/logger.ts new file mode 100644 index 000000000..34cc54b56 --- /dev/null +++ b/demo/utils/logger.ts @@ -0,0 +1 @@ +export default console; diff --git a/package.json b/package.json index fa593db23..f1ea543bd 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "files": [ "dist" ], - "bin": "dist/cli.cjs", + "bin": "dist/cli/index.cjs", "main": "./dist/index.cjs", "module": "./dist/index.js", "types": "./dist/index.d.ts", @@ -25,13 +25,19 @@ "require": "./dist/index.cjs", "import": "./dist/index.js", "types": "./dist/index.d.ts" + }, + "./client": { + "require": "./dist/client/index.cjs", + "import": "./dist/client/index.js", + "types": "./dist/client/index.d.ts" } }, "scripts": { "dev": "tsx src/cli.ts", "build": "run-s build:*", "build:js": "tsup src/index.ts --clean --sourcemap --dts --format esm,cjs", - "build:cli": "tsup src/cli.ts", + "build:cli": "tsup src/cli/index.ts -d dist/cli --sourcemap", + "build:client": "tsup src/client/index.ts -d dist/client --sourcemap --dts --format esm,cjs", "format": "prettier --write .", "format:check": "prettier --write .", "prepare": "simple-git-hooks" diff --git a/src/cli.ts b/src/cli.ts deleted file mode 100644 index 641dd4caf..000000000 --- a/src/cli.ts +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env node - -import cac from 'cac'; -import { version } from '../package.json'; -import * as commands from './commands'; - -const cli = cac('exvite'); -cli.help(); -cli.version(version); - -// DEV -cli - .command('[root]', 'start dev server') - .option('-c, --config