@@ -9,44 +9,49 @@ const resolve = (path: string) => fileURLToPath(new URL(path, import.meta.url));
99
1010// https://vitejs.dev/config/
1111export default defineConfig ( ( configEnv ) => {
12+ // Default shared config by all modes.
1213 const config : UserConfig = {
13- plugins : [
14- vue ( ) ,
15- vueDevtools ( ) ,
16- dts ( {
17- tsconfigPath : "tsconfig.build.json" ,
18- cleanVueFileName : true ,
19- } ) ,
20- ] ,
21-
14+ plugins : [ vue ( ) ] ,
2215 resolve : {
23- alias : {
24- "@" : resolve ( "./src" ) ,
25- } ,
16+ alias : { "@" : resolve ( "./src" ) } ,
2617 } ,
18+ } ;
2719
28- build : {
29- target : "es2015" ,
30- lib : {
31- name : "vue3-select-component" ,
32- entry : resolve ( "./src/index.ts" ) ,
33- formats : [ "es" , "umd" ] ,
34- fileName : ( format ) => `index.${ format } .js` ,
35- } ,
36- rollupOptions : {
37- external : [ "vue" ] ,
38- output : {
39- globals : { vue : "Vue" } ,
20+ // Build library when in production mode (npm run build).
21+ if ( configEnv . mode === "production" ) {
22+ return {
23+ ...config ,
24+
25+ plugins : [
26+ ...config . plugins ! ,
27+ dts ( { tsconfigPath : "tsconfig.build.json" , cleanVueFileName : true } ) ,
28+ ] ,
29+
30+ build : {
31+ target : "es2015" ,
32+ lib : {
33+ name : "vue3-select-component" ,
34+ entry : resolve ( "./src/index.ts" ) ,
35+ formats : [ "es" , "umd" ] ,
36+ fileName : ( format ) => `index.${ format } .js` ,
37+ } ,
38+ rollupOptions : {
39+ external : [ "vue" ] ,
40+ output : { globals : { vue : "Vue" } } ,
4041 } ,
4142 } ,
42- } ,
43- } ;
43+ } ;
44+ }
45+
46+ if ( [ "development" , "development:playground" , "development:website" ] . includes ( configEnv . mode ) ) {
47+ config . plugins ! . push ( vueDevtools ( ) ) ;
48+ }
4449
45- if ( configEnv . mode === "playground" ) {
50+ if ( configEnv . mode . includes ( "playground" ) ) {
4651 config . root = resolve ( "./playground" ) ;
4752 }
4853
49- if ( configEnv . mode === "website" ) {
54+ if ( configEnv . mode . includes ( "website" ) ) {
5055 config . root = resolve ( "./website" ) ;
5156 }
5257
0 commit comments