-
Notifications
You must be signed in to change notification settings - Fork 216
Expand file tree
/
Copy pathvite.config.ts
More file actions
50 lines (47 loc) · 2.08 KB
/
vite.config.ts
File metadata and controls
50 lines (47 loc) · 2.08 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
import type { UserConfigFn } from 'vite';
import { overrideVaadinConfig } from './vite.generated';
const customConfig: UserConfigFn = (env) => ({
// Here you can add custom Vite parameters
// https://vitejs.dev/config/
plugins: [
{
name: 'filter-out-external-deps',
transform(code, id) {
if (id.endsWith('frontend/generated/flow/generated-flow-webcomponent-imports.js')) {
return code
.split('\n')
.filter((row) => {
// Filter out all imports that are not exported web components.
// Vaadin components and Flow resources such as connectors are already included in the
// DSP bundle, so they don't need to be imported again here.
if (!row.startsWith('import')) return false;
if (row.includes('@vaadin')) return false;
if (row.includes('generated/jar-resources')) return false;
return true;
})
.join('\n');
}
},
},
{
name: 'apply-docs-theme',
transform(code, id) {
// This module is imported by web components exported from Flow to inject styles into their
// shadow root. Instead of importing the docs styles from the Flow bundle again, for example
// by adding @CssImport to DemoExporter, we provide a global from the docs
// (example-resources.ts) that runs the same applyTheme function that is also used in the
// docs to inject styles into Lit / React examples. This way the styles are only loaded
// once, through the DSP bundle.
if (id.endsWith('generated/css.generated.js')) {
return 'export const applyCss = window.__applyTheme.applyTheme;';
}
// Remove applyCss(document) from `generated/vaadin-web-component.ts` because the global theme
// styles injection is handled by `init.ts` in the docs project.
if (id.endsWith('generated/vaadin-web-component.ts')) {
return code.replace('applyCss(document);', '');
}
},
},
],
});
export default overrideVaadinConfig(customConfig);