Repository navigation
Expand file tree
/
Copy pathvite.config.mjs
More file actions
61 lines (57 loc) · 1.78 KB
/
Copy pathvite.config.mjs
File metadata and controls
61 lines (57 loc) · 1.78 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
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { defineConfig } from 'vite';
const rootDir = path.dirname(fileURLToPath(import.meta.url));
const { version } = JSON.parse(fs.readFileSync(path.join(rootDir, 'package.json'), 'utf8'));
export function camelize(value) {
return value.replace(/(?:^\w|[A-Z]|\b\w)/g, (word, index) => (
index === 0 ? word.toLowerCase() : word.toUpperCase()
)).replace(/\s+/g, '');
}
export function createViteConfig({
entry = 'src/index.js',
fileName = 'guidechimp',
libraryName = 'GuideChimp',
minify = false,
outDir = 'dist',
emptyOutDir = false,
} = {}) {
return defineConfig({
css: {
preprocessorOptions: {
scss: {
loadPaths: [rootDir],
},
},
},
resolve: {
alias: {
'@': path.resolve(rootDir, 'src'),
'test@': path.resolve(rootDir, 'test'),
},
},
build: {
cssMinify: minify,
emptyOutDir,
lib: {
entry: path.resolve(rootDir, entry),
name: libraryName,
formats: ['umd'],
fileName: () => `${fileName}.js`,
cssFileName: fileName,
},
minify,
outDir: path.resolve(rootDir, outDir),
sourcemap: true,
target: 'es2015',
rollupOptions: {
output: {
banner: `/*! ${libraryName} v${version} | Copyright (C) ${new Date().getFullYear()} Labs64 GmbH */`,
exports: 'default',
},
},
},
});
}
export default createViteConfig({ emptyOutDir: true });