-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite-library.config.js
56 lines (49 loc) · 1.84 KB
/
vite-library.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
import { resolve } from 'path'
import { defineConfig } from 'vite'
import rollupPluginSizes from 'rollup-plugin-sizes'
import preactPlugin from '@preact/preset-vite'
/** @type {import('vite').PluginOption[]} */
const plugins = [preactPlugin()]
export default defineConfig(({ mode, command }) => {
const BASE_URL = process.env.BASE_URL || ''
console.log(`[Vite] Base URL: ${BASE_URL}`)
const MANAGE_API_URL =
process.env.MANAGE_API_URL || 'https://manage.develop.lb.cs.dm.unipi.it/api/v0'
console.log(`[Vite] Manage API: ${MANAGE_API_URL}`)
// url to manage (no trailing slash)
const MANAGE_URL = process.env.MANAGE_URL || 'https://manage.develop.lb.cs.dm.unipi.it'
console.log(`[Vite] Manage: ${MANAGE_URL}`)
return {
define: {
'process.env.NODE_ENV': JSON.stringify(mode),
'process.env.BASE_URL': JSON.stringify(BASE_URL),
'process.env.MANAGE_URL': JSON.stringify(MANAGE_URL),
'process.env.MANAGE_API_URL': JSON.stringify(MANAGE_API_URL),
},
server: {
port: 3000,
},
build: {
outDir: 'out/lib/',
emptyOutDir: false,
minify: 'terser',
lib: {
formats: ['iife'],
entry: [resolve(__dirname, 'src/element.jsx')],
name: 'DMPlanimetrie',
fileName: 'dm-planimetrie-element',
},
rollupOptions: {
output: {
assetFileNames: 'dm-planimetrie-element.[ext]',
},
},
},
plugins:
command === 'build'
? // mostro alcune metriche sul bundle generato
[...plugins, rollupPluginSizes()]
: // altrimenti non usiamo nessun plugin per ora
[...plugins],
}
})