-
-
Notifications
You must be signed in to change notification settings - Fork 238
/
vite.config.js
121 lines (112 loc) · 3.1 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import pkg from './package.json'
import autoprefixer from 'autoprefixer'
// const isProduction = process.env.NODE_ENV === 'production'
const banner = `/**
* ${pkg.name} v${pkg.version}
* (c) ${new Date().getFullYear()} ${pkg.author}
* @license MIT
*/\n`
const bundlingConf = {
minify: 'terser',
lib: {
entry: resolve(__dirname, 'src/vue-cal/index.vue'),
name: 'vuecal' // For IIFE.
},
rollupOptions: {
// Make sure to externalize deps that shouldn't be bundled into library.
external: ['vue'],
output: [
// Works with dynamic import().
{
format: 'es',
dir: 'dist',
entryFileNames: 'vue-cal.[format].js',
chunkFileNames: '[name].js',
banner,
manualChunks(id) {
const match = /i18n\/(.{2,5})\.json/.exec(id)
if (match) return 'i18n/' + match[1] + '.es'
else if (id.includes('drag-and-drop')) return 'drag-and-drop.es'
}
},
// Works with dynamic import().
{
format: 'cjs',
dir: 'dist',
entryFileNames: 'vue-cal.[format].js',
chunkFileNames: '[name].js',
banner,
manualChunks(id) {
const match = /i18n\/(.{2,5})\.json/.exec(id)
if (match) return 'i18n/' + match[1] + '.cjs'
else if (id.includes('drag-and-drop')) return 'drag-and-drop.cjs'
}
},
// Works with dynamic import().
{
format: 'amd',
name: 'vuecal',
dir: 'dist',
entryFileNames: 'vue-cal.[format].js',
chunkFileNames: '[name].js',
// Provide global variables to use in the UMD build for externalized deps.
globals: { vue: 'Vue' },
banner,
manualChunks(id) {
const match = /i18n\/(.{2,5})\.json/.exec(id)
if (match) return 'i18n/' + match[1] + '.amd'
else if (id.includes('drag-and-drop')) return 'drag-and-drop.amd'
}
},
// IIFE & UMD don't work with dynamic import().
{
format: 'iife',
name: 'vuecal',
inlineDynamicImports: true, // Everything contained in a single file.
dir: 'dist',
entryFileNames: 'vue-cal.[format].js',
chunkFileNames: '[name].js',
// Provide global variables to use in the UMD build for externalized deps.
globals: { vue: 'Vue' }
}
]
}
}
const build = process.env.BUNDLE ? bundlingConf : { outDir: 'docs' }
export default defineConfig({
define: {
'process.env': {
...process.env,
VITE_APP_VERSION: process.env.npm_package_version
}
},
plugins: [
vue({
template: {
compilerOptions: {
whitespace: 'preserve'
}
}
})
], // https://vitejs.dev/config/
resolve: {
alias: {
'@': resolve(__dirname, '/src')
}
},
css: {
preprocessorOptions: {
scss: {
api: 'modern-compiler',
additionalData: '@import "@/scss/_variables.scss";'
}
},
postcss: {
plugins: [autoprefixer]
}
},
build
})