This commit is contained in:
Luke Hagar
2023-11-07 17:12:34 -08:00
5 changed files with 32 additions and 6 deletions

View File

@@ -3,8 +3,13 @@
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "vite dev",
"build": "vite build",
"dev": "pnpm build-dev && run-p run:chrome watch",
"build-dev": "vite build --mode development && pnpm replace-background-path && pnpm build-content-script",
"watch": "watch 'pnpm build-dev' src static",
"build": "vite build && pnpm replace-background-path && pnpm build-content-script",
"run:chrome": "web-ext run -t chromium -s build",
"replace-background-path": "cd build; sed -i \"\" \"s#\\$BACKGROUND_PATH#$(find app -wholename '*/immutable/background.*.js')#g\" manifest.json; cd -",
"build-content-script": "esbuild src/content.ts --bundle --minify --outdir=build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
@@ -38,8 +43,9 @@
"tslib": "^2.6.2",
"typescript": "^5.2.2",
"vite": "^4.4.11",
"vitest": "^0.34.6"
"vitest": "^0.34.6",
"npm-run-all": "^4.1.5",
"watch": "^1.0.2"
},
"type": "module"
}

1
src/background.ts Normal file
View File

@@ -0,0 +1 @@
console.log('hello from background script')

1
src/content.ts Normal file
View File

@@ -0,0 +1 @@
console.log('hello from content script')

View File

@@ -10,5 +10,15 @@
"default_popup": "index.html",
"default_icon": "favicon.png",
"default_title": "sveltekit-extension-template"
},
"background": {
"service_worker": "$BACKGROUND_PATH",
"type": "module"
},
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"js": ["content.js"]
}
]
}

View File

@@ -1,9 +1,17 @@
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vitest/config';
import { fileURLToPath } from 'url';
export default defineConfig({
plugins: [sveltekit()],
test: {
include: ['src/**/*.{test,spec}.{js,ts}']
},
build: {
rollupOptions: {
input: {
background: fileURLToPath(new URL('./src/background.ts', import.meta.url)),
}
}
}
});