|
1 | 1 | import type { ConfigEnv } from 'vite' |
| 2 | +import fs from 'node:fs' |
| 3 | +import path from 'node:path' |
2 | 4 | import { defineConfig } from 'wxt' |
3 | 5 | import ViteConfig from './vite.config' |
4 | 6 |
|
| 7 | +function getRootPackageVersion() { |
| 8 | + let dir = __dirname |
| 9 | + while (dir !== path.parse(dir).root) { |
| 10 | + const pkgPath = path.join(dir, `package.json`) |
| 11 | + if (fs.existsSync(pkgPath)) { |
| 12 | + const pkg = JSON.parse(fs.readFileSync(pkgPath, `utf-8`)) |
| 13 | + if (pkg.version) |
| 14 | + return pkg.version |
| 15 | + } |
| 16 | + dir = path.dirname(dir) |
| 17 | + } |
| 18 | + return `0.0.0` |
| 19 | +} |
| 20 | + |
| 21 | +const version = getRootPackageVersion() |
| 22 | + |
5 | 23 | export default defineConfig({ |
6 | 24 | srcDir: `src`, |
7 | 25 | modulesDir: `src/modules`, |
8 | 26 | manifest: ({ mode, browser }) => ({ |
9 | 27 | name: `公众号内容编辑器`, |
| 28 | + version, |
10 | 29 | icons: { |
11 | 30 | 256: mode === `development` ? `/mpmd/icon-256-gray.png` : `/mpmd/icon-256.png`, |
12 | 31 | }, |
@@ -68,11 +87,18 @@ export default defineConfig({ |
68 | 87 |
|
69 | 88 | return { |
70 | 89 | ...config, |
71 | | - plugins: config.plugins!.filter(plugin => |
72 | | - typeof plugin === `object` |
73 | | - && plugin !== null |
74 | | - && !(`name` in plugin && plugin.name === `vite-plugin-Radar`), |
75 | | - ), |
| 90 | + plugins: config.plugins!.filter((plugin) => { |
| 91 | + if (typeof plugin === `object` && plugin != null && `name` in plugin && plugin?.name === `vite-plugin-Radar`) { |
| 92 | + return false |
| 93 | + } |
| 94 | + if (Array.isArray(plugin)) { |
| 95 | + const first = plugin[0] |
| 96 | + if (typeof first === `object` && first != null && `name` in first && first.name === `vite-plugin-pwa`) { |
| 97 | + return false |
| 98 | + } |
| 99 | + } |
| 100 | + return true |
| 101 | + }), |
76 | 102 | define: undefined, |
77 | 103 | build: undefined, |
78 | 104 | base: `/`, |
|
0 commit comments