-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvite.config.js
More file actions
77 lines (72 loc) · 1.94 KB
/
Copy pathvite.config.js
File metadata and controls
77 lines (72 loc) · 1.94 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
import { sveltekit } from '@sveltejs/kit/vite';
import { nodeLoaderPlugin } from '@vavite/node-loader/plugin';
import basicSsl from '@vitejs/plugin-basic-ssl';
import { defineConfig } from 'vite';
import { paraglideVitePlugin } from '@inlang/paraglide-js';
import * as dotenv from 'dotenv';
import fs from 'fs';
import path from 'path';
dotenv.config();
// Plugin to fix SvelteKit-generated tsconfig.json with deprecated TypeScript options
const fixTsconfig = () => {
const tsconfigPath = path.resolve('.svelte-kit/tsconfig.json');
if (fs.existsSync(tsconfigPath)) {
try {
const config = JSON.parse(fs.readFileSync(tsconfigPath, 'utf-8'));
if (config.compilerOptions) {
config.compilerOptions.verbatimModuleSyntax = true;
delete config.compilerOptions.importsNotUsedAsValues;
delete config.compilerOptions.preserveValueImports;
fs.writeFileSync(tsconfigPath, JSON.stringify(config, null, '\t') + '\n');
}
} catch {
// Ignore errors
}
}
};
const fixTsconfigPlugin = () => ({
name: 'fix-tsconfig',
buildStart() {
fixTsconfig();
},
configureServer() {
// Also fix on dev server start
fixTsconfig();
}
});
export default defineConfig(({ mode }) => {
let plugins = [
sveltekit(),
fixTsconfigPlugin(),
paraglideVitePlugin({
project: './project.inlang',
outdir: './src/lib/i18n',
strategy: ['cookie', 'baseLocale']
})
];
if (mode === 'debug-dev') {
plugins = [nodeLoaderPlugin(), ...plugins];
}
if (process.env.PUBLIC_HTTP_PROTOCOL === 'https' && process.env.PUBLIC_DEV_SSL === 'true')
plugins = [basicSsl(), ...plugins];
return {
build: {
sourcemap: true
},
css: {
devSourcemap: true
},
test: {
include: [
'**/tests/vitest/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}',
'src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'
]
},
plugins,
server: {
port: parseInt(process.env.SERVER_PORT || process.env.PORT || '5173'),
host: '0.0.0.0',
allowedHosts: true
}
};
});