-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathvite.config.mjs
More file actions
202 lines (190 loc) · 6.58 KB
/
vite.config.mjs
File metadata and controls
202 lines (190 loc) · 6.58 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import path from "path";
import copy from "rollup-plugin-copy";
import { defineConfig } from "vite";
const { manifestPlugin } = await import("vite-plugin-simple-manifest").then(
(m) => m.default || m,
);
const entries = {
"css/splide": "./node_modules/@splidejs/splide/dist/css/splide-core.min.css",
"css/styleguide":
"./node_modules/@helsingborg-stad/styleguide/source/sass/main.scss",
"js/styleguide":
"./node_modules/@helsingborg-stad/styleguide/source/js/app.js",
"css/municipio": "./assets/source/sass/main.scss",
"css/mce": "./assets/source/sass/mce.scss",
"css/blockeditor": "./assets/source/sass/blockeditor.scss", // depends on styleguide
"css/acf": "./assets/source/sass/admin/acf.scss",
"css/header-flexible": "./assets/source/sass/admin/header-flexible.scss",
"css/general": "./assets/source/sass/admin/general.scss",
"css/a11y": "./assets/source/sass/admin/a11y.scss",
"css/login": "./assets/source/sass/admin/login.scss",
"css/trash-page": "./assets/source/sass/admin/trash-page.scss",
"fonts/material/light/sharp": "./assets/source/sass/icons/light/sharp.scss",
"fonts/material/light/outlined":
"./assets/source/sass/icons/light/outlined.scss",
"fonts/material/light/rounded":
"./assets/source/sass/icons/light/rounded.scss",
"fonts/material/medium/sharp": "./assets/source/sass/icons/medium/sharp.scss",
"fonts/material/medium/outlined":
"./assets/source/sass/icons/medium/outlined.scss",
"fonts/material/medium/rounded":
"./assets/source/sass/icons/medium/rounded.scss",
"fonts/material/bold/sharp": "./assets/source/sass/icons/bold/sharp.scss",
"fonts/material/bold/outlined":
"./assets/source/sass/icons/bold/outlined.scss",
"fonts/material/bold/rounded": "./assets/source/sass/icons/bold/rounded.scss",
"js/municipio": "./assets/source/js/municipio.js",
"js/instantpage": "./node_modules/instant.page/instantpage.js",
"js/mce-buttons": "./assets/source/mce-js/mce-buttons.js",
"js/mce-table": "./assets/source/mce-js/mce-table.js",
"js/pdf": "./assets/source/js/pdf.ts",
"js/nav": "./assets/source/js/nav.ts",
/* Blocks */
"js/backdrop-banner": "./library/BackdropBanner/js/Front/backdrop-banner.ts",
"css/backdrop-banner": "./library/BackdropBanner/js/Front/backdrop-banner.scss",
"css/backdrop-banner-editor": "./library/BackdropBanner/js/Editor/backdrop-banner.scss",
/* Admin js */
"js/color-picker": "./assets/source/js/admin/colorPicker.js",
"js/design-share": "./assets/source/js/admin/designShare.ts",
"js/customizer-preview": "./assets/source/js/admin/customizerPreview.js",
"js/customizer-flexible-header":
"./assets/source/js/admin/customizerFlexibleHeader.ts",
"js/hidden-post-status-conditional":
"./assets/source/js/admin/acf/hiddenPostStatusConditional.ts",
"js/user-group-visibility":
"./assets/source/js/admin/private/userGroupVisibility.ts",
"js/widgets-area-hider": "./assets/source/js/admin/widgetsAreaHider.js",
"js/customizer-error-handling":
"./assets/source/js/admin/customizerErrorHandling.ts",
"js/blocks/columns": "./assets/source/js/admin/blocks/columns.js",
"js/event-source-progress":
"./assets/source/js/admin/eventSourceProgress/index.ts",
};
export default defineConfig(({ mode }) => {
const isProduction = mode === "production";
return {
build: {
outDir: "assets/dist",
emptyOutDir: true,
lib: false, // Disable lib mode to avoid ES modules
rollupOptions: {
input: entries,
external: ["jquery", "tinymce"],
output: {
manualChunks: (id, { getModuleInfo, getModuleIds }) => {
// Force all modules to be inlined - don't create shared chunks
return null;
},
globals: {
jquery: "jQuery",
tinymce: "tinymce",
},
entryFileNames: isProduction ? "[name].[hash].js" : "[name].js",
chunkFileNames: isProduction ? "[name].[hash].js" : "[name].js",
assetFileNames: (assetInfo) => {
if (assetInfo.name?.endsWith(".css")) {
return isProduction ? "[name].[hash].css" : "[name].css";
}
// Handle font files with custom naming for material symbols
if (assetInfo.name?.match(/\.(woff2?|ttf|eot|svg|otf)$/)) {
const name = assetInfo.name;
if (name.includes("material-symbols")) {
// Extract weight information from source path context
const source = assetInfo.source || "";
// Extract weight and style from filename
let weight = "medium"; // default
let style = "sharp"; // default
if (
name.includes("-200") ||
this.facadeModuleId?.includes("font-200")
) {
weight = "light";
} else if (
name.includes("-400") ||
this.facadeModuleId?.includes("font-400")
) {
weight = "medium";
} else if (
name.includes("-600") ||
this.facadeModuleId?.includes("font-600")
) {
weight = "bold";
}
if (name.includes("outlined")) {
style = "outlined";
} else if (name.includes("rounded")) {
style = "rounded";
}
const ext = name.split(".").pop();
return `fonts/material/${weight}/${style}.[hash].${ext}`;
}
}
return "assets/[name].[hash].[ext]";
},
},
treeshake: {
moduleSideEffects: false,
},
},
minify: isProduction ? "esbuild" : false,
sourcemap: true,
},
// Ensure core-js is included for dependency optimization
optimizeDeps: {
include: ["core-js"],
},
esbuild: {
keepNames: true,
minifyIdentifiers: false,
},
css: {
preprocessorOptions: {
scss: {
quietDeps: true, // Remove when issue is resolved: https://github.com/marella/material-symbols/issues/44
api: "modern-compiler",
includePaths: ["node_modules", "assets/source"],
importers: [
{
findFileUrl(url) {
if (url.startsWith("~")) {
return new URL(
url.slice(1),
new URL("../node_modules/", import.meta.url),
);
}
return null;
},
},
],
},
},
},
resolve: {
extensions: [".tsx", ".ts", ".js", ".scss", ".css"],
alias: {
"~": path.resolve(process.cwd(), "node_modules"),
},
dedupe: ["leaflet"],
},
plugins: [
manifestPlugin("manifest.json"),
copy({
targets: [
{
src: "node_modules/@material-symbols/font-200/*.woff2",
dest: "assets/dist/fonts/material/light/",
},
{
src: "node_modules/@material-symbols/font-400/*.woff2",
dest: "assets/dist/fonts/material/medium/",
},
{
src: "node_modules/@material-symbols/font-600/*.woff2",
dest: "assets/dist/fonts/material/bold/",
},
],
hook: "writeBundle",
}),
],
};
});