-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvite.config.mts
74 lines (60 loc) · 1.82 KB
/
vite.config.mts
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
//@ts-nocheck
import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
import toml from '@fbraem/rollup-plugin-toml';
import fs from 'fs'
import path from 'path'
const folderPath = path.join(__dirname, 'src/plugins'); // Plugin path folder
let plugins = []
try {
const files = fs.readdirSync(folderPath);
// load plugin js sources
plugins = files.filter((file) => {
const filePath = path.join(folderPath, file);
return !file.startsWith('disabled') && fs.statSync(filePath).isDirectory() && fs.statSync(path.join(filePath, 'src/main.js')).isFile();
});
} catch (err) {
console.error('Error:', err);
}
/*
fs.writeFileSync(path.join(__dirname, 'src/javascript/plugins.ts'), `
${plugins.map( (p, i) => `import plugin${i} from '${path.join(__dirname, 'src/plugins', p, 'src/main.js')}'`).join('\n')}
export const plugins = [ ${plugins.map( (p, i) => `plugin${i}`).join(', ')} ]
`)*/
const pluginLoader = {
name: 'mage-plugin-loader',
resolveId ( source ) {
return (source === 'mage-plugins') ? source : null
},
load ( id ) {
if (id === 'mage-plugins') {
// Create a virtual module like:
/*
import '/absolute/path/src/plugins/PLUGIN-NAME/src/main.js'
*/
return plugins.map((p, i) => `import '${path.join(__dirname, 'src/plugins', p, 'src/main.js')}'`).join('\n')
}
return null;
}
};
export default defineConfig({
root: 'src',
base: './',
build: {
emptyOutDir: true,
outDir: '../editor',
},
plugins: [
pluginLoader,
svelte({
preprocess: vitePreprocess(),
onwarn: (warning, handler) => {
// disable a11y warnings
if (warning.code.startsWith("a11y-")) return;
handler(warning);
},
}),
toml(),
]
})