Skip to content

Commit 2817002

Browse files
committed
chore: wip
1 parent d217164 commit 2817002

File tree

8 files changed

+91
-179
lines changed

8 files changed

+91
-179
lines changed

storage/framework/.stacks/core/vite/src/plugin/auto-imports.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { path as p } from '@stacksjs/path'
22
import type { AutoImportsOptions } from '@stacksjs/types'
3-
import { unheadVueComposablesImports } from '@unhead/vue'
3+
import { unheadVueComposablesImports as VueHeadImports } from '@unhead/vue'
44
import { defu } from 'defu'
55
import AutoImport from 'unplugin-auto-import/vite'
66
import type { Plugin } from 'vite'
@@ -9,38 +9,30 @@ import { VueRouterAutoImports } from 'unplugin-vue-router'
99
export function autoImports(options?: AutoImportsOptions): Plugin {
1010
const defaultOptions: AutoImportsOptions = {
1111
imports: [
12+
'pinia',
1213
'vue',
13-
'vue-router',
14-
'vue/macros',
14+
'vue-i18n',
15+
'@vueuse/head',
1516
// '@vueuse/core',
16-
'pinia',
17-
unheadVueComposablesImports,
1817
// 'vitepress'
1918
// { '@stacksjs/ui': ['CssEngine', 'UiEngine', 'Store', 'presetForms', 'transformerCompileClass'] },
2019
// { '@stacksjs/logging': ['dd', 'dump'] }, // we also export `log` in st stacks/cli
2120
// { '@stacksjs/validation': ['validate', 'validateAll', 'validateSync', 'validateAllSync'] },
22-
'vue-i18n',
23-
'@vueuse/head',
21+
VueHeadImports,
2422
VueRouterAutoImports,
2523
{
26-
// add any other imports you were relying on
2724
'vue-router/auto': ['useLink'],
2825
},
2926
],
27+
dts: p.frameworkStoragePath('types/auto-imports.d.ts'),
3028
dirs: [
3129
p.resourcesPath('functions'),
3230
p.resourcesPath('stores'),
33-
p.resourcesPath('components'),
31+
// p.resourcesPath('components'), do we need this?
3432

35-
// here, we say that everything that lives here in .stacks/src/index.ts will be auto-imported
3633
p.frameworkPath('src'),
3734
],
38-
dts: p.frameworkStoragePath('types/auto-imports.d.ts'),
3935
vueTemplate: true,
40-
eslintrc: {
41-
enabled: false,
42-
// filepath: frameworkPath('.eslintrc-auto-import.json'),
43-
},
4436
}
4537

4638
const newOptions = defu(options, defaultOptions)
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import UnoCSS from 'unocss/vite'
22
import { path as p } from '@stacksjs/path'
33

4-
// export function cssEngine(isWebComponent = false) {
5-
export function cssEngine() {
4+
export function cssEngine(isWebComponent = false) {
65
return UnoCSS({
76
configFile: p.uiPath('src/uno.config.ts'),
8-
// mode: isWebComponent ? 'shadow-dom' : 'vu'
7+
mode: isWebComponent ? 'shadow-dom' : 'vue-scoped'
98
})
109
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import WebfontDownload from 'vite-plugin-webfont-dl'
2+
3+
export function fonts() {
4+
// https://github.com/feat-agency/vite-plugin-webfont-dl
5+
return WebfontDownload()
6+
}
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
// export function i18n(options?: i18nOptions) {
2-
// const defaultOptions: i18nOptions = {
3-
// runtimeOnly: true,
4-
// compositionOnly: true,
5-
// include: [langPath('./**')],
6-
// }
1+
import VueI18n from '@intlify/unplugin-vue-i18n/vite'
2+
import { path as p } from '@stacksjs/path'
73

8-
// const newOptions = defu(options, defaultOptions)
9-
10-
// return VueI18n(newOptions)
11-
// }
4+
export function i18n() {
5+
return VueI18n({
6+
runtimeOnly: true,
7+
compositionOnly: true,
8+
fullInstall: true,
9+
include: [
10+
p.resolve(__dirname, '../../../../../../lang/**')
11+
],
12+
})
13+
}
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1+
import { path as p } from '@stacksjs/path'
2+
// @ts-expect-error missing types - somehow, @stacksjs/vite-plugin-vue-layouts does not work
13
import Layouts from 'vite-plugin-vue-layouts'
4+
// @ts-expect-error missing types - somehow, @stacksjs/vite-plugin-vue-layouts does not work
25
import type { UserOptions as LayoutOptions } from 'vite-plugin-vue-layouts'
36

47
export function layouts(options?: LayoutOptions) {
5-
return Layouts(options)
8+
return Layouts({
9+
layoutsDir: p.resourcesPath('layouts'),
10+
defaultLayout: p.resourcesPath('layouts/default.vue'),
11+
exclude: [
12+
p.resourcesPath('layouts/mails'),
13+
],
14+
...options,
15+
})
616
}

storage/framework/.stacks/core/vite/src/plugin/pwa.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { path } from '@stacksjs/path'
12
import { VitePWA } from 'vite-plugin-pwa'
23

34
export function pwa() {
45
return VitePWA({
6+
srcDir: path.publicPath(),
57
registerType: 'autoUpdate',
68
includeAssets: ['favicon.svg', 'safari-pinned-tab.svg'],
79
manifest: {

storage/framework/.stacks/core/vite/src/plugin/ui-engine.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import Vue from '@vitejs/plugin-vue'
22
import type { Plugin } from 'vite'
3+
import Markdown from 'unplugin-vue-markdown/vite'
4+
import LinkAttributes from 'markdown-it-link-attributes'
5+
import Shiki from 'markdown-it-shikiji'
36

47
export function uiEngine(isWebComponent = false): Plugin {
58
const include = [/\.vue$/, /\.md$/]
@@ -19,3 +22,28 @@ export function uiEngine(isWebComponent = false): Plugin {
1922
include,
2023
})
2124
}
25+
26+
export function markdown() {
27+
// https://github.com/unplugin/unplugin-vue-markdown
28+
return Markdown({
29+
wrapperClasses: 'prose prose-sm m-auto text-left',
30+
headEnabled: true,
31+
async markdownItSetup(md) {
32+
md.use(LinkAttributes, {
33+
matcher: (link: string) => /^https?:\/\//.test(link),
34+
attrs: {
35+
target: '_blank',
36+
rel: 'noopener',
37+
},
38+
})
39+
40+
md.use(await Shiki({
41+
defaultColor: false,
42+
themes: {
43+
light: 'vitesse-light',
44+
dark: 'vitesse-dark',
45+
},
46+
}))
47+
},
48+
})
49+
}

storage/framework/.stacks/core/vite/src/views.ts

Lines changed: 23 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -5,67 +5,24 @@ import generateSitemap from 'vite-ssg-sitemap'
55
import { server } from '@stacksjs/server'
66
import { alias } from '@stacksjs/alias'
77
import { config } from '@stacksjs/config'
8-
// @ts-expect-error missing types
8+
// @ts-expect-error missing types - somehow, @stacksjs/vite-plugin-vue-layouts does not work
99
import Layouts from 'vite-plugin-vue-layouts'
10-
import Components from 'unplugin-vue-components/vite'
11-
import AutoImport from 'unplugin-auto-import/vite'
12-
import Markdown from 'unplugin-vue-markdown/vite'
10+
import { autoImports } from './plugin/auto-imports'
11+
import { layouts } from './plugin/layouts'
12+
import { markdown } from './plugin/ui-engine'
13+
import { components } from './plugin/components'
14+
import { i18n } from './plugin/i18n'
15+
import { fonts } from './plugin/fonts'
16+
import { pwa } from './plugin/pwa'
17+
import { cssEngine } from './plugin/css-engine'
1318
import VueMacros from 'unplugin-vue-macros/vite'
14-
import VueI18n from '@intlify/unplugin-vue-i18n/vite'
15-
import { VitePWA } from 'vite-plugin-pwa'
1619
import VueDevTools from 'vite-plugin-vue-devtools'
17-
import LinkAttributes from 'markdown-it-link-attributes'
18-
import Unocss from 'unocss/vite'
19-
import Shiki from 'markdown-it-shikiji'
20-
import WebfontDownload from 'vite-plugin-webfont-dl'
2120
import VueRouter from 'unplugin-vue-router/vite'
22-
import { VueRouterAutoImports } from 'unplugin-vue-router'
2321

2422
// const isMaintenanceMode = config.app.maintenanceMode
2523
// const maintenancePath = isMaintenanceMode ? '' : './maintenance'
2624

2725
export default defineConfig({
28-
build: {
29-
rollupOptions: {
30-
external: ['path', 'fs', 'net', 'tls', 'stream', 'node:process', 'constants', 'node:dns/promises', 'node:util'],
31-
}
32-
},
33-
34-
// define: {
35-
// 'process.env': {
36-
// APP_NAME: JSON.stringify(process.env.APP_NAME),
37-
// APP_ENV: JSON.stringify(process.env.APP_ENV),
38-
// APP_KEY: JSON.stringify(process.env.APP_KEY),
39-
// APP_DEBUG: JSON.stringify(process.env.APP_DEBUG),
40-
// APP_URL: JSON.stringify(process.env.APP_URL),
41-
// APP_PORT: JSON.stringify(process.env.APP_PORT),
42-
// APP_MAINTENANCE: JSON.stringify(process.env.APP_MAINTENANCE),
43-
// DB_CONNECTION: JSON.stringify(process.env.DB_CONNECTION),
44-
// DB_HOST: JSON.stringify(process.env.DB_HOST),
45-
// DB_PORT: JSON.stringify(process.env.DB_PORT),
46-
// DB_DATABASE: JSON.stringify(process.env.DB_DATABASE),
47-
// DB_USERNAME: JSON.stringify(process.env.DB_USERNAME),
48-
// DB_PASSWORD: JSON.stringify(process.env.DB_PASSWORD),
49-
// AWS_ACCESS_KEY_ID: JSON.stringify(process.env.AWS_ACCESS_KEY_ID),
50-
// AWS_SECRET_ACCESS_KEY: JSON.stringify(process.env.AWS_SECRET_ACCESS_KEY),
51-
// AWS_DEFAULT_PASSWORD: JSON.stringify(process.env.AWS_DEFAULT_PASSWORD),
52-
// AWS_REGION: JSON.stringify(process.env.AWS_REGION),
53-
// MAIL_MAILER: JSON.stringify(process.env.MAIL_MAILER),
54-
// MAIL_HOST: JSON.stringify(process.env.MAIL_HOST),
55-
// MAIL_PORT: JSON.stringify(process.env.MAIL_PORT),
56-
// MAIL_USERNAME: JSON.stringify(process.env.MAIL_USERNAME),
57-
// MAIL_PASSWORD: JSON.stringify(process.env.MAIL_PASSWORD),
58-
// MAIL_ENCRYPTION: JSON.stringify(process.env.MAIL_ENCRYPTION),
59-
// MAIL_FROM_NAME: JSON.stringify(process.env.MAIL_FROM_NAME),
60-
// MAIL_FROM_ADDRESS: JSON.stringify(process.env.MAIL_FROM_ADDRESS),
61-
// SEARCH_ENGINE_DRIVER: JSON.stringify(process.env.SEARCH_ENGINE_DRIVER),
62-
// MEILISEARCH_HOST: JSON.stringify(process.env.MEILISEARCH_HOST),
63-
// MEILISEARCH_KEY: JSON.stringify(process.env.MEILISEARCH_KEY),
64-
// FRONTEND_APP_ENV: JSON.stringify(process.env.FRONTEND_APP_ENV),
65-
// FRONTEND_APP_URL: JSON.stringify(process.env.FRONTEND_APP_URL),
66-
// },
67-
// },
68-
6926
root: p.frameworkStoragePath('views'),
7027
publicDir: p.publicPath(),
7128
envDir: p.projectPath(),
@@ -99,117 +56,27 @@ export default defineConfig({
9956
}),
10057

10158
// https://github.com/JohnCampionJr/vite-plugin-vue-layouts
102-
Layouts({
103-
layoutsDir: p.resourcesPath('layouts'),
104-
defaultLayout: p.resourcesPath('layouts/default.vue'),
105-
exclude: [
106-
p.resourcesPath('layouts/mails'),
107-
],
108-
}),
59+
layouts(),
10960

11061
// https://github.com/antfu/unplugin-auto-import
111-
AutoImport({
112-
imports: [
113-
'vue',
114-
'vue-i18n',
115-
'@vueuse/head',
116-
'@vueuse/core',
117-
VueRouterAutoImports,
118-
{
119-
// add any other imports you were relying on
120-
'vue-router/auto': ['useLink'],
121-
},
122-
],
123-
dts: p.frameworkStoragePath('types/auto-imports.d.ts'),
124-
dirs: [
125-
p.resourcesPath('functions'),
126-
p.resourcesPath('stores'),
127-
],
128-
vueTemplate: true,
129-
}),
62+
autoImports(),
13063

13164
// https://github.com/antfu/unplugin-vue-components
132-
Components({
133-
// allow auto load markdown components under `./resources/components/`
134-
extensions: ['vue', 'md'],
135-
// allow auto import and register components used in markdown
136-
include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
137-
dts: p.frameworkStoragePath('types/components.d.ts'),
138-
dirs: [
139-
p.resourcesPath('components'),
140-
],
141-
}),
65+
components(),
14266

14367
// https://github.com/antfu/unocss
14468
// see uno.config.ts for config
145-
Unocss({
146-
configFile: p.uiPath('src/uno.config.ts'),
147-
}),
69+
cssEngine(),
14870

149-
// https://github.com/unplugin/unplugin-vue-markdown
150-
Markdown({
151-
wrapperClasses: 'prose prose-sm m-auto text-left',
152-
headEnabled: true,
153-
async markdownItSetup(md) {
154-
md.use(LinkAttributes, {
155-
matcher: (link: string) => /^https?:\/\//.test(link),
156-
attrs: {
157-
target: '_blank',
158-
rel: 'noopener',
159-
},
160-
})
161-
md.use(await Shiki({
162-
defaultColor: false,
163-
themes: {
164-
light: 'vitesse-light',
165-
dark: 'vitesse-dark',
166-
},
167-
}))
168-
},
169-
}),
71+
markdown(),
17072

17173
// https://github.com/antfu/vite-plugin-pwa
172-
VitePWA({
173-
srcDir: p.publicPath(),
174-
registerType: 'autoUpdate',
175-
includeAssets: ['favicon.svg', 'safari-pinned-tab.svg'],
176-
manifest: {
177-
name: 'Stacks',
178-
short_name: 'Stacks',
179-
theme_color: '#ffffff',
180-
icons: [
181-
{
182-
src: '/pwa-192x192.png',
183-
sizes: '192x192',
184-
type: 'image/png',
185-
},
186-
{
187-
src: '/pwa-512x512.png',
188-
sizes: '512x512',
189-
type: 'image/png',
190-
},
191-
{
192-
src: '/pwa-512x512.png',
193-
sizes: '512x512',
194-
type: 'image/png',
195-
purpose: 'any maskable',
196-
},
197-
],
198-
},
199-
}),
74+
pwa(),
20075

20176
// https://github.com/intlify/bundle-tools/tree/main/packages/unplugin-vue-i18n
202-
VueI18n({
203-
runtimeOnly: true,
204-
compositionOnly: true,
205-
fullInstall: true,
206-
include: [
207-
p.resolve(__dirname, '../../../../../../lang/**')
208-
],
209-
}),
77+
i18n(),
21078

211-
// https://github.com/feat-agency/vite-plugin-webfont-dl
212-
WebfontDownload(),
79+
fonts(),
21380

21481
// https://github.com/webfansplz/vite-plugin-vue-devtools
21582
VueDevTools(),
@@ -233,4 +100,10 @@ export default defineConfig({
233100
// TODO: workaround until they support native ESM
234101
noExternal: ['workbox-window', /vue-i18n/],
235102
},
103+
104+
build: {
105+
rollupOptions: {
106+
external: ['path', 'fs', 'net', 'tls', 'stream', 'node:process', 'constants', 'node:dns/promises', 'node:util'],
107+
}
108+
},
236109
})

0 commit comments

Comments
 (0)