1
1
import vuePlugin from '@vitejs/plugin-vue'
2
- import type { Alias , InlineConfig , UserConfig as ViteUserConfig } from 'vite'
2
+ import type {
3
+ Alias ,
4
+ InlineConfig ,
5
+ Plugin ,
6
+ UserConfig as ViteUserConfig
7
+ } from 'vite'
3
8
import { findDepPkgJsonPath } from 'vitefu'
4
9
import { mergeConfig } from 'vite'
5
10
import { build } from 'esbuild'
@@ -29,7 +34,6 @@ import type { VitrifyPlugin } from './plugins/index.js'
29
34
import { resolve } from './app-urls.js'
30
35
import type { ManualChunksOption , RollupOptions } from 'rollup'
31
36
import { addOrReplaceTitle , appendToBody } from './helpers/utils.js'
32
- import type { ComponentResolver } from 'unplugin-vue-components'
33
37
import Components from 'unplugin-vue-components/vite'
34
38
import { VitePWA } from 'vite-plugin-pwa'
35
39
import UnoCSS from 'unocss/vite'
@@ -50,21 +54,6 @@ const internalServerModules = [
50
54
'abort-controller'
51
55
]
52
56
53
- const configPluginMap : Record < string , ( ) => Promise < VitrifyPlugin > > = {
54
- quasar : ( ) =>
55
- import ( './plugins/quasar.js' ) . then ( ( module ) => module . QuasarPlugin )
56
- }
57
-
58
- const configResolverMap : Record <
59
- string ,
60
- ( ) => Promise < ComponentResolver | ComponentResolver [ ] >
61
- > = {
62
- quasar : ( ) =>
63
- import ( 'unplugin-vue-components/resolvers' ) . then ( ( module ) =>
64
- module . QuasarResolver ( )
65
- )
66
- }
67
-
68
57
const manualChunkNames = [
69
58
'prerender' ,
70
59
'fastify-ssr-plugin' ,
@@ -103,31 +92,6 @@ const manualChunksFn = (manualChunkList?: string[]): ManualChunksOption => {
103
92
}
104
93
}
105
94
106
- // const manualChunks: ManualChunksOption = (
107
- // id: string,
108
- // manualChunkList?: string[]
109
- // ) => {
110
- // const matchedModule = Object.entries(moduleChunks).find(
111
- // ([chunkName, moduleNames]) =>
112
- // moduleNames.some((moduleName) => id.includes(moduleName + '/'))
113
- // )
114
- // if (id.includes('vitrify/src/')) {
115
- // const name = id.split('/').at(-1)?.split('.').at(0)
116
- // if (name && manualChunkNames.includes(name)) return name
117
- // } else if (
118
- // VIRTUAL_MODULES.some((virtualModule) => id.includes(virtualModule))
119
- // ) {
120
- // return VIRTUAL_MODULES.find((name) => id.includes(name))
121
- // } else if (manualChunkList?.some((file) => id.includes(file))) {
122
- // return manualChunkList.find((file) => id.includes(file))
123
- // } else if (id.includes('node_modules')) {
124
- // if (matchedModule) {
125
- // return matchedModule[0]
126
- // }
127
- // return 'vendor'
128
- // }
129
- // }
130
-
131
95
export const VIRTUAL_MODULES = [
132
96
'virtual:vitrify-hooks' ,
133
97
'virtual:static-imports' ,
@@ -241,7 +205,6 @@ export const baseConfig = async ({
241
205
fs . writeFileSync ( configPath + '.js' , bundledConfig . code )
242
206
243
207
rawVitrifyConfig = ( await import ( 'file://' + configPath + '.js' ) ) . default
244
- // vitrifyConfig = (await import(configPath + '.js')).default
245
208
fs . unlinkSync ( configPath + '.js' )
246
209
} else {
247
210
rawVitrifyConfig = (
@@ -258,9 +221,11 @@ export const baseConfig = async ({
258
221
throw e
259
222
}
260
223
261
- const localPackages = [ 'vue' , 'vue-router' , '@vue/server-renderer' ]
262
- // const localPackages: string[] = []
263
- const cliPackages = [ ]
224
+ const localPackages = [ ]
225
+ if ( framework === 'vue' )
226
+ localPackages . push ( 'vue' , 'vue-router' , '@vue/server-renderer' )
227
+
228
+ const cliPackages : string [ ] = [ ]
264
229
const packageUrls : Record < string , URL > =
265
230
vitrifyConfig . vitrify ?. urls ?. packages || { }
266
231
await ( async ( ) => {
@@ -269,14 +234,6 @@ export const baseConfig = async ({
269
234
if ( pkgDir ) packageUrls ! [ val ] = new URL ( `file://${ pkgDir } ` )
270
235
}
271
236
} ) ( )
272
-
273
- // await (async () => {
274
- // for (const val of cliPackages)
275
- // packageUrls[val] = getPkgJsonDir(
276
- // new URL(await resolve(val, cliDir!.href))
277
- // )
278
- // })()
279
-
280
237
if ( ! productName ) {
281
238
try {
282
239
; ( { productName } = JSON . parse (
@@ -294,6 +251,11 @@ export const baseConfig = async ({
294
251
295
252
const isPwa = ! ! vitrifyConfig . vitrify ?. pwa || false
296
253
254
+ const frameworkPlugins : Plugin [ ] = [ ]
255
+ if ( framework === 'vue' ) {
256
+ frameworkPlugins . push ( vuePlugin ( ) )
257
+ }
258
+
297
259
const vitrifyPlugins : Plugin [ ] = [ ]
298
260
if ( vitrifyConfig . vitrify ?. plugins ) {
299
261
for ( const vitrifyPluginConfig of vitrifyConfig . vitrify . plugins ) {
@@ -381,13 +343,12 @@ export const baseConfig = async ({
381
343
/ < s t y l e l a n g = " s a s s " > ( .* ?) < \/ s t y l e > / ,
382
344
'<style lang="sass">' + sass + '</style>'
383
345
)
384
- // code = code.replace(/<\/style>/, sass + '</style>')
385
346
}
386
347
387
348
return code
388
349
}
389
350
} ,
390
- vuePlugin ( ) ,
351
+ ... frameworkPlugins ,
391
352
...vitrifyPlugins ,
392
353
{
393
354
name : 'vitrify-setup' ,
@@ -448,10 +409,6 @@ export const baseConfig = async ({
448
409
return `import ${ varName } from '${
449
410
new URL ( url , appDir ) . pathname
450
411
} '; onSetup.push(${ varName } )`
451
-
452
- // return `import ${varName} from '${fileURLToPath(
453
- // url
454
- // )}'; onSetup.push(${varName})`
455
412
} )
456
413
. join ( '\n' ) } `
457
414
} else if ( id === 'virtual:static-imports' ) {
@@ -468,11 +425,7 @@ export const baseConfig = async ({
468
425
) ,
469
426
...globalSass . map ( ( sass ) => `@import '${ sass } '` )
470
427
] . join ( '\n' )
471
- }
472
- // else if (id === 'vitrify.css') {
473
- // return `${globalCss.map((css) => `@import '${css}'`).join('\n')}`
474
- // }
475
- else if ( id === 'virtual:vitrify-config' ) {
428
+ } else if ( id === 'virtual:vitrify-config' ) {
476
429
return `export default ${ JSON . stringify ( vitrifyConfig ) } `
477
430
}
478
431
return null
@@ -502,14 +455,14 @@ export const baseConfig = async ({
502
455
}
503
456
} ,
504
457
Components ( {
458
+ ...vitrifyConfig . vitrify ?. unpluginVueComponents ,
505
459
exclude : [
506
460
new RegExp (
507
461
`[\\/]node_modules[\\/].*[\\/]!(${ serverModules . join ( '|' ) } )`
508
462
) ,
509
463
/ [ \\ / ] \. g i t [ \\ / ] / ,
510
464
/ [ \\ / ] \. n u x t [ \\ / ] /
511
- ] ,
512
- resolvers
465
+ ]
513
466
} ) ,
514
467
UnoCSS ( {
515
468
...vitrifyConfig . vitrify ?. unocss ,
@@ -562,32 +515,13 @@ export const baseConfig = async ({
562
515
} else {
563
516
entryScript = `<script type="module" src="${ entry } "></script>`
564
517
}
565
- // html = html.replace('<!--entry-script-->', entryScript)
566
518
html = appendToBody ( entryScript , html )
567
519
if ( productName ) html = addOrReplaceTitle ( productName , html )
568
- // html = html.replace('<!--product-name-->', productName)
569
520
return html
570
521
}
571
522
}
572
523
} )
573
524
574
- // plugins.unshift({
575
- // name: 'product-name',
576
- // enforce: 'post',
577
- // config: (config: VitrifyConfig, env) => {
578
- // if (config.vitrify?.productName)
579
- // productName = config.vitrify?.productName
580
- // return
581
- // },
582
- // transformIndexHtml: {
583
- // enforce: 'post',
584
- // transform: (html) => {
585
- // html = html.replace('<!--product-name-->', productName)
586
- // return html
587
- // }
588
- // }
589
- // })
590
-
591
525
if ( debug ) plugins . push ( visualizer ( ) )
592
526
}
593
527
@@ -602,41 +536,52 @@ export const baseConfig = async ({
602
536
]
603
537
604
538
const vuePkgAliases : Alias [ ] = [ ]
605
- for ( const pkg of vueInternalPkgs ) {
606
- const specifier = pkg . split ( '/' ) . at ( - 1 )
607
- const pkgJsonPath = await findDepPkgJsonPath ( pkg , fileURLToPath ( appDir ! ) )
608
- if ( pkgJsonPath )
609
- vuePkgAliases . push ( {
610
- find : pkg ,
611
- replacement : fileURLToPath (
612
- new URL (
613
- `./dist/${ specifier } .esm-bundler.js` ,
614
- `file://${ pkgJsonPath } ` || ''
539
+ if ( packageUrls [ 'vue' ] ) {
540
+ for ( const pkg of vueInternalPkgs ) {
541
+ const specifier = pkg . split ( '/' ) . at ( - 1 )
542
+ const pkgJsonPath = await findDepPkgJsonPath ( pkg , fileURLToPath ( appDir ! ) )
543
+ if ( pkgJsonPath )
544
+ vuePkgAliases . push ( {
545
+ find : pkg ,
546
+ replacement : fileURLToPath (
547
+ new URL (
548
+ `./dist/${ specifier } .esm-bundler.js` ,
549
+ `file://${ pkgJsonPath } ` || ''
550
+ )
615
551
)
616
- )
617
- } )
552
+ } )
553
+
554
+ vuePkgAliases . push (
555
+ {
556
+ find : new RegExp ( '^vue$' ) ,
557
+ replacement : fileURLToPath (
558
+ new URL ( './dist/vue.runtime.esm-bundler.js' , packageUrls [ 'vue' ] )
559
+ )
560
+ } ,
561
+ {
562
+ find : new RegExp ( '^vue-router$' ) ,
563
+ replacement : fileURLToPath (
564
+ new URL (
565
+ './dist/vue-router.esm-bundler.js' ,
566
+ packageUrls [ 'vue-router' ]
567
+ )
568
+ )
569
+ } ,
570
+ ...vuePkgAliases
571
+ )
572
+ }
618
573
}
619
574
620
575
const alias : Alias [ ] = [
621
576
{ find : 'src' , replacement : fileURLToPath ( srcDir ) } ,
622
577
{ find : 'app' , replacement : fileURLToPath ( appDir ) } ,
623
578
{ find : 'cwd' , replacement : fileURLToPath ( cwd ) } ,
624
579
{ find : 'boot' , replacement : fileURLToPath ( new URL ( 'boot/' , srcDir ) ) } ,
625
- { find : 'assets' , replacement : fileURLToPath ( new URL ( 'assets/' , srcDir ) ) } ,
626
- {
627
- find : new RegExp ( '^vue$' ) ,
628
- replacement : fileURLToPath (
629
- new URL ( './dist/vue.runtime.esm-bundler.js' , packageUrls [ 'vue' ] )
630
- )
631
- } ,
632
- {
633
- find : new RegExp ( '^vue-router$' ) ,
634
- replacement : fileURLToPath (
635
- new URL ( './dist/vue-router.esm-bundler.js' , packageUrls [ 'vue-router' ] )
636
- )
637
- } ,
638
- ...vuePkgAliases
580
+ { find : 'assets' , replacement : fileURLToPath ( new URL ( 'assets/' , srcDir ) ) }
639
581
]
582
+
583
+ if ( framework === 'vue' ) alias . push ( ...vuePkgAliases )
584
+
640
585
if ( mode === 'development' && vitrifyConfig . vitrify ?. dev ?. alias )
641
586
alias . push ( ...vitrifyConfig . vitrify . dev . alias )
642
587
0 commit comments