1
1
import type { CmsConfig } from 'netlify-cms-core' ;
2
2
import type { OutputBundle } from 'rollup' ;
3
3
import type { Plugin } from 'vite' ;
4
+ import type { PreviewStyle } from './types' ;
4
5
5
6
const dashboardPath = 'astro-netlify-cms/cms' ;
6
7
7
- const AdminPage = ( {
8
+ function AdminPage ( {
8
9
adminPath,
9
10
assets,
10
11
config,
11
- dashboardPath,
12
12
previewStyles = [ ] ,
13
13
} : {
14
14
adminPath : string ;
15
15
config : CmsConfig ;
16
16
previewStyles : Array < string | [ string ] | [ string , { raw : boolean } ] > ;
17
- } & (
18
- | { assets : [ id : string , filename : string ] [ ] ; dashboardPath ?: undefined }
19
- | { assets ?: undefined ; dashboardPath : string }
20
- ) ) => {
17
+ /** Array of module ID and filename tuples present only at build time. */
18
+ assets ?: [ id : string , filename : string ] [ ] ;
19
+ } ) {
21
20
const imports : string [ ] = [ ] ;
22
21
const styles : string [ ] = [ ] ;
23
22
@@ -65,7 +64,7 @@ const AdminPage = ({
65
64
<body></body>
66
65
</html>
67
66
` ;
68
- } ;
67
+ }
69
68
70
69
export default function AdminDashboardPlugin ( {
71
70
adminPath,
@@ -74,7 +73,7 @@ export default function AdminDashboardPlugin({
74
73
} : {
75
74
adminPath : string ;
76
75
config : Omit < CmsConfig , 'load_config_file' | 'local_backend' > ;
77
- previewStyles : Array < string | [ string ] | [ string , { raw : boolean } ] > ;
76
+ previewStyles : PreviewStyle [ ] ;
78
77
} ) : Plugin {
79
78
if ( ! adminPath . startsWith ( '/' ) ) {
80
79
throw new Error (
@@ -92,6 +91,7 @@ export default function AdminDashboardPlugin({
92
91
return {
93
92
name : 'vite-plugin-netlify-cms-admin-dashboard' ,
94
93
94
+ /** Build-only Rollup hook. */
95
95
options ( options ) {
96
96
let { input } = options ;
97
97
if (
@@ -101,14 +101,14 @@ export default function AdminDashboardPlugin({
101
101
) {
102
102
if ( ! Array . isArray ( input ) && typeof input !== 'object' ) input = [ input ] ;
103
103
importMap = generateImportMap ( {
104
- dashboardPath,
105
104
previewStyles,
106
105
} ) ;
107
106
input = { ...input , ...importMap } ;
108
107
}
109
108
return { ...options , input } ;
110
109
} ,
111
110
111
+ /** Dev-only Vite hook. */
112
112
configureServer ( { transformIndexHtml, middlewares } ) {
113
113
middlewares . use ( async ( req , res , next ) => {
114
114
if ( req . url === adminPath || req . url === adminPath + '/' ) {
@@ -117,7 +117,6 @@ export default function AdminDashboardPlugin({
117
117
AdminPage ( {
118
118
adminPath,
119
119
config,
120
- dashboardPath,
121
120
previewStyles,
122
121
} )
123
122
) ;
@@ -128,6 +127,7 @@ export default function AdminDashboardPlugin({
128
127
} ) ;
129
128
} ,
130
129
130
+ /** Build-only Rollup hook. */
131
131
generateBundle ( options , bundle ) {
132
132
const dashboardChunk = Object . values ( bundle ) . find (
133
133
( { name } ) => name === 'cms'
@@ -163,10 +163,8 @@ interface ImportMap {
163
163
* ```
164
164
*/
165
165
function generateImportMap ( {
166
- dashboardPath,
167
166
previewStyles,
168
167
} : {
169
- dashboardPath : string ;
170
168
previewStyles : Array < string | [ string ] | [ string , { raw : boolean } ] > ;
171
169
} ) : ImportMap {
172
170
const imports : ImportMap = { cms : dashboardPath } ;
0 commit comments