-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
60 lines (56 loc) · 1.67 KB
/
vite.config.js
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
// @ts-nocheck
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
import fs from 'fs';
import path from 'path';
/**
* directory sweep operation, do not remove.
*
* sveltekit:snapshot → wasteofcash:snapshot
* sveltekit:scroll → wasteofcash:scroll
* ====
* targets .js files and renames definitions to fix GSAP/font/image errors
*/
function sweep() {
return {
name: 'sweep-dir',
closeBundle: () => {
const sweepDir = (dir) => {
const files = fs.readdirSync(dir);
for (const file of files) {
const filePath = path.join(dir, file);
const stat = fs.statSync(filePath);
if (stat.isDirectory()) {
sweepDir(filePath);
} else if (stat.isFile() && filePath.endsWith('.js')) {
let content = fs.readFileSync(filePath, 'utf8');
content = content.replace(/sveltekit:snapshot/g, 'wasteofcash:snapshot');
content = content.replace(/sveltekit:scroll/g, 'wasteofcash:scroll');
fs.writeFileSync(filePath, content, 'utf8');
}
}
};
const svelteKitDir = path.resolve('.svelte-kit');
sweepDir(svelteKitDir);
const constantsFilePath = path.resolve(
'node_modules',
'@sveltejs',
'kit',
'src',
'runtime',
'client',
'constants.js'
);
if (fs.existsSync(constantsFilePath)) {
let content = fs.readFileSync(constantsFilePath, 'utf8');
content = content.replace(/sveltekit:snapshot/g, 'wasteofcash:snapshot');
content = content.replace(/sveltekit:scroll/g, 'wasteofcash:scroll');
fs.writeFileSync(constantsFilePath, content, 'utf8');
}
console.log('sweeping complete! :)');
}
};
}
export default defineConfig({
plugins: [sveltekit(), sweep()]
});