11import { dirname , resolve } from 'node:path'
22import { fileURLToPath } from 'node:url'
3- import { defineConfig } from 'vite'
3+ import { defineConfig , transformWithEsbuild } from 'vite'
44import vue from '@vitejs/plugin-vue'
55import dts from 'vite-plugin-dts'
66import tailwindcss from '@tailwindcss/vite'
77
88const __dirname = dirname ( fileURLToPath ( import . meta. url ) )
99
10+ const esbuildMinify = {
11+ name : 'minify-plugin' ,
12+ renderChunk ( code ) {
13+ return transformWithEsbuild ( code , 'index.js' , {
14+ minify : true ,
15+ treeShaking : true ,
16+ } )
17+ }
18+ }
19+
1020export default defineConfig ( {
1121 define : {
1222 'process.env.NODE_ENV' : JSON . stringify ( 'production' )
@@ -31,27 +41,39 @@ export default defineConfig({
3141 build : {
3242 minify : false ,
3343 lib : {
34- entry : {
35- index : resolve ( __dirname , 'src/index.ts' ) ,
36- components : resolve ( __dirname , 'src/components/index.ts' ) ,
37- scale : resolve ( __dirname , 'src/js/scale.js' ) ,
38- break : resolve ( __dirname , 'src/js/break.js' ) ,
39- label : resolve ( __dirname , 'src/js/label.js' ) ,
40- theme : resolve ( __dirname , 'src/js/theme.js' ) ,
41- } ,
44+ entry : resolve ( __dirname , 'src/index.ts' ) ,
4245 name : 'VVPlot' ,
43- formats : [ 'es' ] ,
46+ fileName : 'vvplot' ,
4447 cssFileName : "style"
4548 } ,
4649 rollupOptions : {
4750 external : [ 'vue' ] ,
48- output : {
49- chunkFileNames : '[name].js' ,
50- minifyInternalExports : false ,
51- globals : {
52- vue : 'Vue' ,
51+ output : [
52+ {
53+ format : 'es' ,
54+ entryFileNames : 'vvplot.esm.js' ,
55+ minifyInternalExports : false ,
56+ } ,
57+ {
58+ format : 'es' ,
59+ entryFileNames : 'vvplot.esm.min.js' ,
60+ plugins : [ esbuildMinify ]
61+ } ,
62+ {
63+ format : 'iife' ,
64+ name : 'VVPlot' ,
65+ entryFileNames : 'vvplot.global.js' ,
66+ minifyInternalExports : false ,
67+ globals : { vue : 'Vue' } ,
68+ } ,
69+ {
70+ format : 'iife' ,
71+ name : 'VVPlot' ,
72+ entryFileNames : 'vvplot.global.min.js' ,
73+ globals : { vue : 'Vue' } ,
74+ plugins : [ esbuildMinify ]
5375 } ,
54- } ,
76+ ] ,
5577 } ,
5678 } ,
5779} )
0 commit comments