我有浏览器扩展(打字),通过Vite与plugin CRXJS构建.构建后,创建了包含精简脚本的文件夹,但跳过了manifest.web_accessible_resources
中的脚本(用于注入到网页).
我需要做什么才能在构建时缩小文件src/injection.js
?此时,文件只需复制-粘贴到输出文件夹.
// manifest.ts
import { defineManifest } from '@crxjs/vite-plugin'
export default defineManifest({
"manifest_version": 3,
"permissions": ["storage"],
"content_scripts": [
{
"run_at": "document_start",
"matches": [
"https://*.example.com/*"
],
"js": [
"src/content/content.ts"
]
}
],
"action": {
"default_popup": "src/popup.html"
},
"background": {
"service_worker": "src/background/background.ts"
},
"icons": {
"48": "assets/icons/icon48.png",
},
"web_accessible_resources": [
{
"matches": [
"https://*.example.com/*"
],
"resources": [
"src/injection.js",
],
"use_dynamic_url": true,
}
],
})
// vite.config.ts
import { defineConfig } from 'vite'
import { crx } from '@crxjs/vite-plugin'
import { svelte } from '@sveltejs/vite-plugin-svelte'
import path from 'path'
import sveltePreprocess from 'svelte-preprocess'
import manifest from './src/manifest';
export default defineConfig(({ mode }) => {
const production = mode === 'production'
return {
build: {
minify: true,
emptyOutDir: true,
outDir: 'build',
rollupOptions: {
output: {
return 'assets/[name]-[hash][extname]';
},
},
}
},
plugins: [
crx({ manifest }),
svelte({
compilerOptions: {
dev: !production,
},
preprocess: sveltePreprocess(),
}),
],
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
},
},
}
})