Repository navigation
Expand file tree
/
Copy pathvite.config.lib.mjs
More file actions
66 lines (61 loc) · 1.77 KB
/
Copy pathvite.config.lib.mjs
File metadata and controls
66 lines (61 loc) · 1.77 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
62
63
64
65
66
import { resolve } from 'node:path'
import { defineConfig } from 'vite'
import banner from 'vite-plugin-banner'
import pkg from './package.json'
// CommonJS needs a .cjs extension: package.json is "type": "module", so Node reads any .js as ESM
const LIB_FILE_SUFFIX = { es: 'es.js', cjs: 'cjs', umd: 'umd.js' }
const bannerTemplate = `
/**
${pkg.name} - ${pkg.homepage}
Version: ${pkg.version}
Author: ${pkg.author}
*/
`
export default defineConfig(({ mode }) => {
const isMinified = mode === 'production-minified'
return {
root: './',
build: {
lib: {
entry: resolve(__dirname, 'src/lib/js/index.js'),
name: 'formeo',
fileName: format => `[name].${isMinified ? 'min.' : ''}${LIB_FILE_SUFFIX[format]}`,
formats: ['es', 'cjs', 'umd'],
},
outDir: 'dist',
emptyOutDir: false, // Don't empty on each build to preserve both versions
minify: isMinified ? 'terser' : false,
terserOptions: isMinified
? {
compress: {
drop_console: true,
drop_debugger: true,
},
}
: undefined,
rollupOptions: {
input: {
formeo: resolve(__dirname, 'src/lib/js/index.js'),
},
output: {
assetFileNames: isMinified ? 'formeo.min.[ext]' : 'formeo.[ext]',
inlineDynamicImports: true,
},
},
},
plugins: [banner(bannerTemplate)],
css: {
preprocessorOptions: {
scss: {
api: 'modern-compiler',
},
},
},
resolve: {
dedupe: ['@draggable/i18n'], // Prevents multiple bundling instances of the linked package
},
optimizeDeps: {
exclude: ['@draggable/i18n'], // Excludes the linked package from pre-bundling for live updates
},
}
})