-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvite.config.js
166 lines (153 loc) · 4.61 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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/* eslint-env node */
import { createHtmlPlugin } from 'vite-plugin-html';
import path from 'path';
import glob from 'glob';
// import postcss from 'postcss';
// import cssInJS from '@stylelint/postcss-css-in-js';
export default ({ mode }) => {
let input = {};
const dirname = path.dirname(new URL(import.meta.url).pathname);
const isProduction = mode === 'production';
// For production we need to specify all our entry points
// See https://vitejs.dev/guide/build.html#multi-page-app
if (isProduction) {
input.main = path.resolve(dirname, 'index.html');
const componentPages = glob.sync('pages/components/**/*.html', {
absolute: true,
});
const pages = glob.sync('pages/*.html', {
absolute: true,
});
for (const page of pages.concat(componentPages)) {
const fileName = path.parse(page).name;
input[fileName] = page;
}
}
const injectOptions = {
ejsOptions: {
views: ['pages/includes'],
},
};
return {
// base: isProduction ? '/elements/' : '',
plugins: [
// litElementTailwindPlugin({ mode }),
createHtmlPlugin({
minify: false,
pages: [
{
filename: 'button.html',
template: 'pages/components/button.html',
injectOptions,
},
{
filename: 'alert.html',
template: 'pages/components/alert.html',
injectOptions,
},
{
filename: 'select.html',
template: 'pages/components/select.html',
injectOptions,
},
{
filename: 'attention.html',
template: 'pages/components/attention.html',
injectOptions,
},
{
filename: 'box.html',
template: 'pages/components/box.html',
injectOptions,
},
{
filename: 'breadcrumbs.html',
template: 'pages/components/breadcrumbs.html',
injectOptions,
},
{
filename: 'broadcast.html',
template: 'pages/components/broadcast.html',
injectOptions,
},
{
filename: 'card.html',
template: 'pages/components/card.html',
injectOptions,
},
{
filename: 'toast.html',
template: 'pages/components/toast.html',
injectOptions,
},
{
filename: 'textfield.html',
template: 'pages/components/textfield.html',
injectOptions,
},
{
filename: 'expandable.html',
template: 'pages/components/expandable.html',
injectOptions,
},
{
filename: 'index.html',
template: 'index.html',
injectOptions,
},
],
}),
isProduction && basePathFix(),
],
build: {
outDir: 'site',
rollupOptions: {
input,
},
},
};
};
// Tiny plugin to to use Tailwind classes with lit-element
// See postcss.config.js
// function litElementTailwindPlugin({ mode }) {
// // FIXME: This is to simple a check... if we start adding utility files etc that we import in our web components we'll process them as well
// function shouldProcess(id) {
// // try to match all JS files that follows this pattern ./packages/*/src/*.js
// return id.match(/(.*)\/packages\/(.*)\/src\/(.*).js$/);
// // return !id.includes('node_modules') && id.endsWith('.js');
// }
// return {
// name: 'lit-element-tailwind-plugin',
// async transform(code, id) {
// if (shouldProcess(id)) {
// // postcss context
// const context = {
// env: mode,
// file: {
// extname: path.extname(id),
// dirname: path.dirname(id),
// basename: path.basename(id),
// },
// };
// const result = await postcss(
// require('./postcss.config')(context).plugins,
// ).process(code, {
// from: undefined,
// syntax: cssInJS,
// });
// return {
// code: result.css,
// };
// }
// },
// };
// }
function basePathFix() {
return {
name: 'base-path-fix',
transformIndexHtml(html) {
// Replace pages/components with '' for production build.
return html.replace(/pages\/components\//g, '');
},
};
}