-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvite.config.ts
77 lines (74 loc) · 2.37 KB
/
vite.config.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
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
import {defineConfig} from "vitest/config"
import i18nextLoader from "vite-plugin-i18next-loader"
import fs from "fs";
import * as path from "path";
import * as child_process from "child_process";
import md5 from "crypto-js/md5";
function serverExport() {
return {
name: 'server-export',
buildStart() {
this.addWatchFile(path.resolve(__dirname, 'web/src/server-export.ts'))
},
writeBundle(options, bundle) {
console.log(child_process.execSync("npm run server-export").toString());
},
};
}
const cssModulesJson = {}
// https://vitejs.dev/config/
// https://vitest.dev/config/
export default defineConfig(({command}) => ({
root: "web",
plugins: [
i18nextLoader({
paths: ['./web/src/locales'],
namespaceResolution: 'basename',
}),
serverExport(),
],
build: {
outDir: "../target/web-dist/public",
emptyOutDir: true,
sourcemap: true,
rollupOptions: {
output: {
entryFileNames: "assets/[name].[hash].js",
assetFileNames: "assets/[name].[hash][extname]",
},
},
},
css: {
modules: {
getJSON: (cssFileName: string,
json: Record<string, string>,
_outputFileName: string) => {
// The generated CSS class names differ between production and development mode.
// We should write css-modules.json only when building the static CSS assets.
// If "vite dev" would update css-modules.json, some of the CSS class names would
// get out of sync with the previously built CSS file.
if (command === 'build') {
const match = cssFileName.match(/\/(\w+)\.module\.css/)
const key = match ? match[1] : cssFileName
cssModulesJson[key] = json;
const file = "target/web-dist/css-modules.json";
fs.mkdirSync(path.dirname(file), {recursive: true})
fs.writeFileSync(file, JSON.stringify(cssModulesJson, null, 2))
}
},
generateScopedName: function (local, filename, css) {
filename = filename.split('?')[0]; // remove "?used" suffix
filename = path.basename(filename, ".module.css"); // remove .module.css suffix
const hash = md5(css).toString().substring(0, 8);
return `${filename}__${local}--${hash}`;
},
}
},
test: {
globals: true,
environment: "jsdom",
cache: {
dir: "../node_modules/.vitest"
}
}
}))