-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.plugins.ts
38 lines (34 loc) · 1.18 KB
/
vite.plugins.ts
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
35
36
37
38
import { IOptionalPreprocessOptions, preprocess } from '@aurelia/plugin-conventions';
import { createFilter } from '@rollup/pluginutils';
import * as rollupPluginutils from 'rollup-pluginutils';
import { Plugin } from 'vite';
export function au2({ include, exclude, ...options }: { include?: string; exclude?: string; pre?: boolean } & IOptionalPreprocessOptions) {
const filter = createFilter(include, exclude);
return {
name: 'au2',
enforce: options.pre ? 'pre' : 'post',
transform: function transform(code: string, id: string) {
if (!filter(id)) return;
const result = preprocess(
{
path: id,
contents: code,
},
{ hmr: true, hmrModule: 'import.meta', ...options },
)?.code;
return { code: result ?? code };
},
} as Plugin;
}
export const rawHtml = () => {
const filter = rollupPluginutils.createFilter('**/*.ts', undefined);
return {
name: 'raw',
transform: function transform(code: string, id: string) {
if (!filter(id)) return;
if (code.includes('__au2ViewDef')) return;
code = code.replaceAll(/(import .* from .*)\.html/g, '$1.html?raw');
return { code };
},
};
};