Skip to content

Commit d61b2c9

Browse files
honwhyyanglbme
authored andcommitted
feat: update for build chrome extension
1 parent e7e3682 commit d61b2c9

4 files changed

Lines changed: 45 additions & 9 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ pnpm web build:h5-netlify
113113

114114
# Chrome 插件启动及调试
115115
pnpm web ext:dev
116-
# 访问 chrome://extensions/ 打开开发者模式,加载已解压的扩展程序,选择 .output/chrome-mv3-dev 目录
116+
# 访问 chrome://extensions/ 打开开发者模式,加载已解压的扩展程序,选择 apps/web/.output/chrome-mv3-dev 目录
117117

118118
# Chrome 插件打包
119119
pnpm web ext:zip
120120

121121
# Firefox 扩展打包(how to build Firefox addon)
122-
pnpm web firefox:zip # output zip file at in .output/md-{version}-firefox.zip
122+
pnpm web firefox:zip # output zip file at in apps/web/.output/md-{version}-firefox.zip
123123

124124
# uTools 插件打包
125125
pnpm utools:package # output zip file at apps/utools/release/md-utools-v{version}.zip

apps/web/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
"wrangler:deploy": "cross-env CF_WORKERS=1 pnpm run build:h5-netlify && wrangler deploy",
2222
"release:cli": "node ./scripts/release.js",
2323
"ext:dev": "wxt",
24-
"ext:zip": "wxt zip",
24+
"ext:zip": "cross-env NODE_OPTIONS=--max-old-space-size=4096 wxt zip",
2525
"firefox:dev": "wxt -b firefox",
26-
"firefox:zip": "wxt zip -b firefox",
26+
"firefox:zip": "cross-env NODE_OPTIONS=--max-old-space-size=4096 wxt zip -b firefox",
2727
"type-check": "vue-tsc --build --force",
2828
"postinstall": "wxt prepare",
2929
"package:extension": "pnpm --prefix ./src/extension run package"

apps/web/web-ext.config.ts.example

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { defineWebExtConfig } from 'wxt'
2+
3+
export default defineWebExtConfig({
4+
// binaries: {
5+
// chrome: 'D:/Applications/Scoop/shims/chrome.exe', // Use Chrome Beta instead of regular Chrome
6+
// firefox: 'D:/Applications/Scoop/shims/firefox.exe', // Use Firefox Developer Edition instead of regular Firefox
7+
// edge: '/path/to/edge', // Open MS Edge when running "wxt -b edge"
8+
// },
9+
disabled: true
10+
})

apps/web/wxt.config.ts

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
11
import type { ConfigEnv } from 'vite'
2+
import fs from 'node:fs'
3+
import path from 'node:path'
24
import { defineConfig } from 'wxt'
35
import ViteConfig from './vite.config'
46

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+
523
export default defineConfig({
624
srcDir: `src`,
725
modulesDir: `src/modules`,
826
manifest: ({ mode, browser }) => ({
927
name: `公众号内容编辑器`,
28+
version,
1029
icons: {
1130
256: mode === `development` ? `/mpmd/icon-256-gray.png` : `/mpmd/icon-256.png`,
1231
},
@@ -68,11 +87,18 @@ export default defineConfig({
6887

6988
return {
7089
...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+
}),
76102
define: undefined,
77103
build: undefined,
78104
base: `/`,

0 commit comments

Comments
 (0)