Repository navigation
Expand file tree
/
Copy pathvite.config.js
More file actions
66 lines (64 loc) · 2.06 KB
/
Copy pathvite.config.js
File metadata and controls
66 lines (64 loc) · 2.06 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 babelPresetEnv from '@babel/preset-env';
import { getBabelOutputPlugin } from '@rollup/plugin-babel';
import vitePluginVue2 from '@vitejs/plugin-vue2';
import babelPresetMinify from 'babel-preset-minify';
import { defineConfig } from 'vite';
export default defineConfig(function({ mode }) {
const isBrowserBuild = mode === 'browser' || mode === 'browser-min';
const shouldMinify = mode === 'browser-min';
const minSuffix = shouldMinify ? '.min' : '';
return {
plugins: [
vitePluginVue2(),
...(isBrowserBuild ? [] : [{
name: 'no-css',
generateBundle(options, bundle) {
for (const key of Object.keys(bundle)) {
if (key.endsWith('.css')) {
delete bundle[key];
}
}
}
}])
],
build: {
lib: {
entry: resolve(import.meta.dirname, isBrowserBuild ? 'src/browser-wrapper.js' : 'src/plugin.js'),
name: 'EmbettyVue',
formats: isBrowserBuild ? ['iife'] : ['es', 'cjs'],
fileName: isBrowserBuild
? () => `embetty-vue.browser${minSuffix}.js`
: (format) => (format === 'es' ? 'embetty-vue.mjs' : 'embetty-vue.cjs')
},
rollupOptions: {
external: isBrowserBuild ? ['vue'] : ['vue', 'vue-ts-types'],
output: {
globals: {
vue: 'Vue'
},
...(
isBrowserBuild
? {
assetFileNames: () => `embetty-vue${minSuffix}.css`,
plugins: [
getBabelOutputPlugin({
allowAllFormats: true,
presets: [
[babelPresetEnv, { targets: { ie: 11 } }],
...(shouldMinify ? [babelPresetMinify] : [])
]
})
]
}
: { exports: 'named' }
)
}
},
cssCodeSplit: false,
cssMinify: shouldMinify ? 'esbuild' : false,
minify: shouldMinify ? 'esbuild' : false,
emptyOutDir: false
}
};
});