File tree 9 files changed +33
-8
lines changed
9 files changed +33
-8
lines changed Original file line number Diff line number Diff line change @@ -290,6 +290,19 @@ export default {
290
290
}
291
291
```
292
292
293
+ ### assetsDir
294
+
295
+ - Type: ` string `
296
+ - Default: ` assets `
297
+
298
+ The directory for assets files. See also: [ assetsDir] ( https://vitejs.dev/config/build-options.html#build-assetsdir ) .
299
+
300
+ ``` ts
301
+ export default {
302
+ assetsDir: ' static'
303
+ }
304
+ ```
305
+
293
306
### cacheDir
294
307
295
308
- Type: ` string `
Original file line number Diff line number Diff line change @@ -58,7 +58,10 @@ export function pathToFile(path: string) {
58
58
pageHash = __VP_HASH_MAP__ [ pagePath . toLowerCase ( ) ]
59
59
}
60
60
if ( ! pageHash ) return null
61
- pagePath = `${ base } assets/${ pagePath } .${ pageHash } .js`
61
+ pagePath = `${ base } ${ __ASSETS_DIR__ . replace (
62
+ / " ( .+ ) " / ,
63
+ '$1'
64
+ ) } /${ pagePath } .${ pageHash } .js`
62
65
} else {
63
66
// ssr build uses much simpler name mapping
64
67
pagePath = `./${ sanitizeFileName (
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ declare const __VP_LOCAL_SEARCH__: boolean
3
3
declare const __ALGOLIA__ : boolean
4
4
declare const __CARBON__ : boolean
5
5
declare const __VUE_PROD_DEVTOOLS__ : boolean
6
+ declare const __ASSETS_DIR__ : string
6
7
7
8
declare module '*.vue' {
8
9
import type { DefineComponent } from 'vue'
Original file line number Diff line number Diff line change @@ -94,19 +94,19 @@ export async function bundle(
94
94
output : {
95
95
sanitizeFileName,
96
96
...rollupOptions ?. output ,
97
- assetFileNames : 'assets /[name].[hash].[ext]' ,
97
+ assetFileNames : ` ${ config . assetsDir } /[name].[hash].[ext]` ,
98
98
...( ssr
99
99
? {
100
100
entryFileNames : '[name].js' ,
101
101
chunkFileNames : '[name].[hash].js'
102
102
}
103
103
: {
104
- entryFileNames : 'assets /[name].[hash].js' ,
104
+ entryFileNames : ` ${ config . assetsDir } /[name].[hash].js` ,
105
105
chunkFileNames ( chunk ) {
106
106
// avoid ads chunk being intercepted by adblock
107
107
return / (?: C a r b o n | B u y S e l l ) A d s / . test ( chunk . name )
108
- ? 'assets /chunks/ui-custom.[hash].js'
109
- : 'assets /chunks/[name].[hash].js'
108
+ ? ` ${ config . assetsDir } /chunks/ui-custom.[hash].js`
109
+ : ` ${ config . assetsDir } /chunks/[name].[hash].js`
110
110
} ,
111
111
manualChunks ( id , ctx ) {
112
112
if ( lazyDefaultThemeComponentsRE . test ( id ) ) {
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ export async function renderPage(
46
46
// for any initial page load, we only need the lean version of the page js
47
47
// since the static content is already on the page!
48
48
const pageHash = pageToHashMap [ pageName . toLowerCase ( ) ]
49
- const pageClientJsFileName = `assets /${ pageName } .${ pageHash } .lean.js`
49
+ const pageClientJsFileName = `${ config . assetsDir } /${ pageName } .${ pageHash } .lean.js`
50
50
51
51
let pageData : PageData
52
52
let hasCustom404 = true
Original file line number Diff line number Diff line change @@ -73,6 +73,9 @@ export async function resolveConfig(
73
73
} )
74
74
const site = await resolveSiteData ( root , userConfig )
75
75
const srcDir = normalizePath ( path . resolve ( root , userConfig . srcDir || '.' ) )
76
+ const assetsDir = userConfig . assetsDir
77
+ ? userConfig . assetsDir . replace ( / \/ / g, '' )
78
+ : 'assets'
76
79
const outDir = userConfig . outDir
77
80
? normalizePath ( path . resolve ( root , userConfig . outDir ) )
78
81
: resolve ( root , 'dist' )
@@ -94,6 +97,7 @@ export async function resolveConfig(
94
97
const config : SiteConfig = {
95
98
root,
96
99
srcDir,
100
+ assetsDir,
97
101
site,
98
102
themeDir,
99
103
pages,
Original file line number Diff line number Diff line change @@ -129,7 +129,8 @@ export async function createVitePressPlugin(
129
129
__ALGOLIA__ :
130
130
site . themeConfig ?. search ?. provider === 'algolia' ||
131
131
! ! site . themeConfig ?. algolia , // legacy
132
- __CARBON__ : ! ! site . themeConfig ?. carbonAds
132
+ __CARBON__ : ! ! site . themeConfig ?. carbonAds ,
133
+ __ASSETS_DIR__ : JSON . stringify ( siteConfig . assetsDir )
133
134
} ,
134
135
optimizeDeps : {
135
136
// force include vue to avoid duplicated copies when linked + optimized
Original file line number Diff line number Diff line change @@ -28,7 +28,8 @@ export async function serve(options: ServeOptions = {}) {
28
28
const config = await resolveConfig ( options . root , 'serve' , 'production' )
29
29
const base = trimChar ( options ?. base ?? config ?. site ?. base ?? '' , '/' )
30
30
31
- const notAnAsset = ( pathname : string ) => ! pathname . includes ( '/assets/' )
31
+ const notAnAsset = ( pathname : string ) =>
32
+ ! pathname . includes ( `/${ config . assetsDir } /` )
32
33
const notFound = fs . readFileSync ( path . resolve ( config . outDir , './404.html' ) )
33
34
const onNoMatch : IOptions [ 'onNoMatch' ] = ( req , res ) => {
34
35
res . statusCode = 404
Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ export interface UserConfig<ThemeConfig = any>
59
59
srcDir ?: string
60
60
srcExclude ?: string [ ]
61
61
outDir ?: string
62
+ assetsDir ?: string
62
63
cacheDir ?: string
63
64
64
65
shouldPreload ?: ( link : string , page : string ) => boolean
@@ -192,6 +193,7 @@ export interface SiteConfig<ThemeConfig = any>
192
193
configDeps : string [ ]
193
194
themeDir : string
194
195
outDir : string
196
+ assetsDir : string
195
197
cacheDir : string
196
198
tempDir : string
197
199
pages : string [ ]
You can’t perform that action at this time.
0 commit comments