-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
vite.config.js
94 lines (80 loc) · 2.13 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
import { defineConfig } from 'vite';
import externalGlobals from 'rollup-plugin-external-globals';
import banner from 'vite-plugin-banner';
import { readFileSync } from 'fs';
import vitePostCSSSourceMap from './scripts/vite-plugins/vitePostCSSSourceMap.mjs';
const pkg = JSON.parse(readFileSync('package.json', 'utf-8'));
const version = pkg.version;
const date = (new Date()).toISOString().replace(/:\d+\.\d+Z$/, 'Z');
const banners = {
'default': `
Super simple WYSIWYG editor v${version}
https://summernote.org
Copyright 2013- Hackerwins and contributors
Summernote may be freely distributed under the MIT license.
Date: ${date}
`,
'minimal': `Summernote v${version} | (c) 2013- Hackerwins and contributors | MIT license`,
};
const styles = [
'lite',
'bs3', 'bs4', 'bs5',
];
const defaultStyle = 'lite';
let configs = {};
for (const style of styles) {
configs[style] = defineConfig({
// prevent to build twice while calling `build` function manually
configFile: false,
resolve: {
alias: {
'@': '/src',
},
},
plugins: [
externalGlobals({
jquery: '$',
}),
banner((fileName) => {
if (fileName.endsWith('.min.js')) return banners['minimal'];
if (fileName.endsWith('.js')) return banners['default'];
}),
vitePostCSSSourceMap(),
],
css: {
preprocessorOptions: {
scss: {
api: 'modern',
},
},
},
build: {
sourcemap: true,
lib: {
entry: `/src/styles/${style}/summernote-${style}.js`,
name: 'summernote',
formats: ['iife'],
fileName: (format, entryName) => `${entryName}.js`,
},
rollupOptions: {
external: (id) => {
if (id === 'jquery') return true; // do not bundle jQuery
if (id.startsWith('./font/')) return true; // do not bundle font files
return false;
},
output: {
assetFileNames: `summernote-${style}.[ext]`,
globals: {
jquery: 'jQuery',
},
},
},
},
});
}
export default configs[defaultStyle];
export {
configs,
banners,
version,
};