Skip to content

Commit d912d12

Browse files
authored
chore: support launch editor in development (#978)
* chore: support launch editor in development * fix: wxt prepare error
1 parent 8601dcc commit d912d12

File tree

3 files changed

+116
-96
lines changed

3 files changed

+116
-96
lines changed

CONTRIBUTING.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ pnpm web dev
9292

9393
6. 在 GitHub 页面发起 **Pull Request**
9494

95+
> [!TIP]
96+
> 开发时可在 `apps/web` 目录下新建 `.env.local` 文件,配置 `VITE_LAUNCH_EDITOR``code` (默认值)或其他 [支持的编辑器](https://github.com/yyx990803/launch-editor?tab=readme-ov-file#supported-editors),方便调试。
97+
>
98+
> 例如:
99+
>
100+
> ```
101+
> VITE_LAUNCH_EDITOR=cursor
102+
> ```
103+
95104
## 代码规范
96105
97106
- 遵循项目自带的 **ESLint**、**Prettier** 与 **Stylelint** 配置。

apps/web/vite.config.ts

Lines changed: 91 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -6,101 +6,107 @@ import vue from '@vitejs/plugin-vue'
66
import { visualizer } from 'rollup-plugin-visualizer'
77
import AutoImport from 'unplugin-auto-import/vite'
88
import Components from 'unplugin-vue-components/vite'
9-
import { defineConfig } from 'vite'
9+
import { defineConfig, loadEnv } from 'vite'
1010
import { nodePolyfills } from 'vite-plugin-node-polyfills'
1111
import { VitePWA } from 'vite-plugin-pwa'
1212
import { VitePluginRadar } from 'vite-plugin-radar'
1313
import vueDevTools from 'vite-plugin-vue-devtools'
1414

1515
const base = process.env.SERVER_ENV === `NETLIFY` ? `/` : `/md/`
1616

17-
export default defineConfig({
18-
base,
19-
define: { process },
20-
envPrefix: [`VITE_`, `CF_`],
21-
plugins: [
22-
vue(),
23-
tailwindcss(),
24-
vueDevTools(),
25-
VitePWA({
26-
registerType: `autoUpdate`,
27-
includeAssets: [`favicon.ico`],
28-
manifest: {
29-
name: `@doocs-md`,
30-
short_name: `@doocs-md`,
31-
theme_color: `#ffffff`,
32-
icons: [
33-
{
34-
src: `${base}pwa-192x192.png`,
35-
sizes: `192x192`,
36-
type: `image/png`,
37-
},
38-
{
39-
src: `${base}pwa-512x512.png`,
40-
sizes: `512x512`,
41-
type: `image/png`,
42-
},
43-
{
44-
src: `${base}pwa-512x512.png`,
45-
sizes: `512x512`,
46-
type: `image/png`,
47-
purpose: `any maskable`,
48-
},
49-
],
50-
},
51-
workbox: {
52-
maximumFileSizeToCacheInBytes: 6 * 1024 * 1024,
53-
},
54-
devOptions: {
55-
enabled: true,
56-
},
57-
}),
58-
nodePolyfills({
59-
include: [`path`, `util`, `timers`, `stream`, `fs`],
60-
overrides: {
17+
export default defineConfig(({ mode }) => {
18+
const env = loadEnv(mode, process.cwd())
19+
20+
return {
21+
base,
22+
define: { process },
23+
envPrefix: [`VITE_`, `CF_`],
24+
plugins: [
25+
vue(),
26+
tailwindcss(),
27+
vueDevTools({
28+
launchEditor: env.VITE_LAUNCH_EDITOR ?? `code`,
29+
}),
30+
VitePWA({
31+
registerType: `autoUpdate`,
32+
includeAssets: [`favicon.ico`],
33+
manifest: {
34+
name: `@doocs-md`,
35+
short_name: `@doocs-md`,
36+
theme_color: `#ffffff`,
37+
icons: [
38+
{
39+
src: `${base}pwa-192x192.png`,
40+
sizes: `192x192`,
41+
type: `image/png`,
42+
},
43+
{
44+
src: `${base}pwa-512x512.png`,
45+
sizes: `512x512`,
46+
type: `image/png`,
47+
},
48+
{
49+
src: `${base}pwa-512x512.png`,
50+
sizes: `512x512`,
51+
type: `image/png`,
52+
purpose: `any maskable`,
53+
},
54+
],
55+
},
56+
workbox: {
57+
maximumFileSizeToCacheInBytes: 6 * 1024 * 1024,
58+
},
59+
devOptions: {
60+
enabled: true,
61+
},
62+
}),
63+
nodePolyfills({
64+
include: [`path`, `util`, `timers`, `stream`, `fs`],
65+
overrides: {
6166
// Since `fs` is not supported in browsers, we can use the `memfs` package to polyfill it.
6267
// fs: 'memfs',
63-
},
64-
}),
65-
VitePluginRadar({
66-
analytics: { id: `G-7NZL3PZ0NK` },
67-
}),
68-
process.env.ANALYZE === `true`
69-
&& visualizer({ emitFile: true, filename: `stats.html` }),
70-
AutoImport({
71-
imports: [`vue`, `pinia`, `@vueuse/core`],
72-
dirs: [`./src/stores`, `./src/utils/toast`, `./src/composables`],
73-
}),
74-
Components({
75-
resolvers: [],
76-
}),
77-
],
78-
resolve: {
79-
alias: { '@': path.resolve(__dirname, `./src`) },
80-
},
81-
css: { devSourcemap: true },
82-
build: {
83-
rollupOptions: {
84-
output: {
85-
chunkFileNames: `static/js/md-[name]-[hash].js`,
86-
entryFileNames: `static/js/md-[name]-[hash].js`,
87-
assetFileNames: `static/[ext]/md-[name]-[hash].[ext]`,
88-
manualChunks(id) {
89-
if (id.includes(`node_modules`)) {
90-
if (id.includes(`katex`))
91-
return `katex`
92-
if (id.includes(`mermaid`))
93-
return `mermaid`
94-
if (id.includes(`highlight.js`))
95-
return `hljs`
96-
const pkg = id
97-
.split(`node_modules/`)[1]
98-
.split(`/`)[0]
99-
.replace(`@`, `npm_`)
100-
return `vendor_${pkg}`
101-
}
68+
},
69+
}),
70+
VitePluginRadar({
71+
analytics: { id: `G-7NZL3PZ0NK` },
72+
}),
73+
process.env.ANALYZE === `true`
74+
&& visualizer({ emitFile: true, filename: `stats.html` }),
75+
AutoImport({
76+
imports: [`vue`, `pinia`, `@vueuse/core`],
77+
dirs: [`./src/stores`, `./src/utils/toast`, `./src/composables`],
78+
}),
79+
Components({
80+
resolvers: [],
81+
}),
82+
],
83+
resolve: {
84+
alias: { '@': path.resolve(__dirname, `./src`) },
85+
},
86+
css: { devSourcemap: true },
87+
build: {
88+
rollupOptions: {
89+
output: {
90+
chunkFileNames: `static/js/md-[name]-[hash].js`,
91+
entryFileNames: `static/js/md-[name]-[hash].js`,
92+
assetFileNames: `static/[ext]/md-[name]-[hash].[ext]`,
93+
manualChunks(id) {
94+
if (id.includes(`node_modules`)) {
95+
if (id.includes(`katex`))
96+
return `katex`
97+
if (id.includes(`mermaid`))
98+
return `mermaid`
99+
if (id.includes(`highlight.js`))
100+
return `hljs`
101+
const pkg = id
102+
.split(`node_modules/`)[1]
103+
.split(`/`)[0]
104+
.replace(`@`, `npm_`)
105+
return `vendor_${pkg}`
106+
}
107+
},
102108
},
103109
},
104110
},
105-
},
111+
}
106112
})

apps/web/wxt.config.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { ConfigEnv } from 'vite'
12
import { defineConfig } from 'wxt'
23
import ViteConfig from './vite.config'
34

@@ -62,15 +63,19 @@ export default defineConfig({
6263
analysis: {
6364
open: true,
6465
},
65-
vite: () => ({
66-
...ViteConfig,
67-
plugins: ViteConfig.plugins!.filter(plugin =>
68-
typeof plugin === `object`
69-
&& plugin !== null
70-
&& !(`name` in plugin && plugin.name === `vite-plugin-Radar`),
71-
),
72-
define: undefined,
73-
build: undefined,
74-
base: `/`,
75-
}),
66+
vite: ({ mode }) => {
67+
const config = ViteConfig({ mode } as ConfigEnv)
68+
69+
return {
70+
...config,
71+
plugins: config.plugins!.filter(plugin =>
72+
typeof plugin === `object`
73+
&& plugin !== null
74+
&& !(`name` in plugin && plugin.name === `vite-plugin-Radar`),
75+
),
76+
define: undefined,
77+
build: undefined,
78+
base: `/`,
79+
}
80+
},
7681
})

0 commit comments

Comments
 (0)