-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvite.config.js
51 lines (46 loc) · 1.23 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
// import { resolve } from 'path';
import { defineConfig } from 'vite';
import { crx } from '@crxjs/vite-plugin';
import vue from '@vitejs/plugin-vue';
import { minify } from 'html-minifier-terser';
import manifest from './src/manifest.config';
// const root = resolve(__dirname, './src');
const imports = `@import '../scss/var';
@import '../scss/mixins';`;
function additionalData(content) {
// If there are @use statements, insert the import after the last one,
// otherwise insert it before all content.
const match = content.match(/@use '[^']+';/g);
if (match) {
const last = match[match.length - 1];
return content.replace(last, `${last}\n${imports}`);
} else {
return `${imports}\n${content}`;
}
}
function htmlMinifyPlugin() {
return {
name: 'html-minify-plugin',
enforce: 'post',
apply: 'build',
transformIndexHtml(html) {
return minify(html, {
removeComments: true,
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true,
minifyURLs: true,
});
},
};
}
export default defineConfig({
plugins: [vue(), crx({ manifest }), htmlMinifyPlugin()],
css: {
preprocessorOptions: {
scss: {
additionalData,
},
},
},
});