-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
104 lines (97 loc) 路 3.13 KB
/
vite.config.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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { defineConfig } from 'vite';
import * as path from 'path';
import replace from '@rollup/plugin-replace';
import { createHtmlPlugin } from 'vite-plugin-html';
import ViteInspector from 'vite-plugin-inspect';
import Unocss from 'unocss/vite';
import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js';
const customElementName = 'web-component-starter';
// https://vitejs.dev/config/
export default defineConfig({
build: {
cssCodeSplit: false,
lib: {
entry: path.resolve(__dirname, 'src/index.ts'),
name: customElementName,
fileName: (format) => `index.${format}.js`,
formats: ['es', 'umd'],
},
rollupOptions: {
// external: /^lit/,
},
},
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
},
},
css: {
preprocessorOptions: {
scss: {
additionalData: ``,
},
},
},
plugins: [
// https://github.com/vitejs/vite/issues/1579#issuecomment-1264626768
cssInjectedByJsPlugin({
styleId: 'uno-css',
topExecutionPriority: false,
// FIXME: should apply style to all web components
// injectCodeFunction: function injectCodeCustomRunTimeFunction(
// cssCode,
// options,
// ) {
// try {
// if (typeof document !== 'undefined') {
// const styleNode = document.createElement('style');
// styleNode.id = options.styleId;
// const cssTextNode = document.createTextNode(cssCode);
// styleNode.appendChild(cssTextNode);
// // query shadowRoot
// const elements =
// document.querySelectorAll('web-component-starter');
// if (elements.length > 0) {
// elements.forEach((ele) => {
// ele.shadowRoot.prepend(
// styleNode
// );
// });
// }
// }
// } catch (e) {
// console.error('vite-plugin-css-injected-by-js', e);
// }
// },
}),
createHtmlPlugin({
minify: true,
/**
* Data that needs to be injected into the index.html ejs template
*/
inject: {
data: {
title: 'web-component-starter',
},
},
}),
// https://github.com/antfu/unocss
// see unocss.config.ts for config
Unocss(),
ViteInspector(),
replace({
preventAssignment: true,
__DATE__: new Date().toISOString(),
}),
],
server: {
port: 8080,
hmr: {
host: '127.0.0.1',
port: 8080,
},
watch: {
ignored: ['**/demo/**'],
},
},
});