generated from unplugin/unplugin-starter
-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathvite.config.base.ts
64 lines (57 loc) · 1.79 KB
/
vite.config.base.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
import fs from 'node:fs'
import path from 'node:path'
import { createResolver } from '@nuxt/kit'
import { defineConfig } from 'vite'
import type { ResolvedConfig } from 'vite'
import Pinceau from 'pinceau/plugin'
import { getPinceauContext } from '@pinceau/core/utils'
import { createSveltePlugin } from '@pinceau/svelte/utils'
import { createReactPlugin } from '@pinceau/react/utils'
import { createVuePlugin } from '@pinceau/vue/utils'
import { configSourceFromModulePath } from '@pinceau/theme/utils'
const resolve = createResolver(import.meta.url).resolve
let config: ResolvedConfig
export default defineConfig({
resolve: {
alias: {
'@pinceau/theme': resolve('../theme/src/index.ts'),
'@pinceau/theme/utils': resolve('../theme/src/utils.ts'),
'@pinceau/core': resolve('../core/src/index.ts'),
'@pinceau/core/utils': resolve('../core/src/utils.ts'),
'@pinceau/integration': resolve('../integration/src/index.ts'),
},
},
plugins: [
Pinceau({
debug: 2,
dev: false,
theme: {
buildDir: path.join(__dirname, '../outputs/'),
},
}),
{
name: '@pinceau/pigments-end',
configResolved(_config) {
config = _config
},
buildEnd() {
const ctx = getPinceauContext(config)
const plugins = {
svelte: createSveltePlugin,
react: createReactPlugin,
vue: createVuePlugin,
}
const outputsPath = configSourceFromModulePath('@pinceau/outputs', ctx)?.path
Object.entries(plugins).forEach(([key, plugin]) => {
const pluginContent = plugin(ctx)
if (outputsPath) {
fs.writeFileSync(
path.join(outputsPath, `${key}-plugin.js`),
pluginContent,
)
}
})
},
},
],
})