-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathvite.config.ts
More file actions
90 lines (88 loc) · 2.22 KB
/
vite.config.ts
File metadata and controls
90 lines (88 loc) · 2.22 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
78
79
80
81
82
83
84
85
86
87
88
89
90
import path from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import dts from 'vite-plugin-dts'
import tailwind from 'tailwindcss'
import autoprefixer from 'autoprefixer'
import type { Plugin } from 'vite'
import postcss from 'postcss'
import prefixer from 'postcss-prefix-selector'
function cssNamespacePlugin(): Plugin {
return {
name: 'vite-plugin-css-namespace',
enforce: 'post',
async generateBundle(_, bundle) {
for (const key of Object.keys(bundle)) {
const chunk = bundle[key]
if (key.endsWith('.css') && 'source' in chunk) {
const css = chunk.source as string
const result = await postcss([
prefixer({
prefix: '.echo-editor',
transform(prefix, selector, prefixedSelector) {
if (
selector.startsWith('.echo-editor') ||
selector.startsWith('.EchoContentView')
) {
return selector;
}
return prefixedSelector;
}
})
]).process(css, { from: undefined });
chunk.source = result.css;
}
}
}
}
}
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
dts({
insertTypesEntry: true,
outDir: 'lib',
exclude: ['src/demo/**/*', 'examples/**/*']
}),
cssNamespacePlugin(),
],
optimizeDeps: {
include: ['vue'],
exclude: ['examples/*', 'src/demo/*']
},
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
css: {
postcss: {
plugins: [tailwind(), autoprefixer()] as any,
},
},
build: {
outDir: 'lib',
lib: {
entry: path.resolve(__dirname, 'src/index.ts'),
name: 'EchoEditor',
fileName: (format) => `echo-editor.${format}.js`,
},
cssCodeSplit: false,
rollupOptions: {
output: {
exports: 'named',
globals: {
vue: 'vue',
},
assetFileNames: (info) => {
if (info.name && info.name.endsWith('.css')) {
return 'style.css';
}
return 'assets/[name].[hash][extname]';
}
},
external: ['vue'],
},
},
})