forked from toss/granite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrouterPlugin.ts
More file actions
34 lines (30 loc) · 779 Bytes
/
Copy pathrouterPlugin.ts
File metadata and controls
34 lines (30 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import type { GranitePluginCore } from '@granite-js/plugin-core';
import { generateRouterFile } from './generateRouterFile';
import { watchRouter } from './watchRouter';
interface RouterPluginOptions {
watch?: boolean;
}
const DEFAULT_OPTIONS: Required<RouterPluginOptions> = {
watch: true,
};
export const router = (options: RouterPluginOptions = DEFAULT_OPTIONS): GranitePluginCore => {
const resolvedOptions = { ...DEFAULT_OPTIONS, ...options };
return {
name: 'router-plugin',
build: {
order: 'pre',
handler: () => {
generateRouterFile();
},
},
dev: {
order: 'pre',
handler: () => {
generateRouterFile();
if (resolvedOptions.watch) {
watchRouter();
}
},
},
};
};