11import path from 'path' ;
22import { fileURLToPath } from 'url' ;
33import { execSync } from 'child_process' ;
4- import { defineConfig , loadEnv , ConfigEnv , LibraryFormats } from 'vite' ;
5- import type { PreRenderedAsset } from 'rollup' ;
4+ import { defineConfig , loadEnv , ConfigEnv } from 'vite' ;
5+ import type { OutputOptions , PreRenderedAsset } from 'rollup' ;
66import react from '@vitejs/plugin-react-swc' ;
77import checker from 'vite-plugin-checker' ;
88import { nodePolyfills } from 'vite-plugin-node-polyfills' ;
@@ -97,28 +97,10 @@ const plugins = [
9797 } ) ,
9898] . filter ( Boolean ) ;
9999
100- const optimizeDeps = { } ;
101-
102- const output : {
103- assetFileNames : ( assetInfo : PreRenderedAsset ) => string ;
104- inlineDynamicImports : boolean ;
105- exports : 'named' | 'default' | 'none' | 'auto' ;
106- } = {
107- assetFileNames : ( assetInfo : PreRenderedAsset ) => {
108- if ( assetInfo . name === 'main.css' ) {
109- return '[name][extname]' ;
110- }
111- return '[name]-[hash][extname]' ;
112- } ,
113- inlineDynamicImports : false ,
114- exports : 'named' as const ,
115- } ;
116-
117100export default defineConfig ( ( { command, mode } : ConfigEnv ) => {
118101 const env = loadEnv ( mode , process . cwd ( ) , '' ) ;
119102 const isHosted = ! ! env . VITE_BUILD_HOSTED ;
120103 const isNetlify = ! ! env . VITE_BUILD_NETLIFY ;
121- const isAnalyze = process . env . ANALYZE === 'true' ;
122104
123105 if ( command === 'serve' || ( command === 'build' && isNetlify ) ) {
124106 // Local development
@@ -133,11 +115,19 @@ export default defineConfig(({ command, mode }: ConfigEnv) => {
133115 main : 'src/SampleApp.tsx' ,
134116 index : 'index.html' ,
135117 } as Record < string , string > ,
136- output,
118+ output : {
119+ assetFileNames : ( assetInfo : PreRenderedAsset ) => {
120+ if ( assetInfo . name === 'main.css' ) {
121+ return '[name][extname]' ;
122+ }
123+ return '[name]-[hash][extname]' ;
124+ } ,
125+ inlineDynamicImports : false ,
126+ exports : 'named' as const ,
127+ } ,
137128 } ,
138129 } ,
139130 plugins,
140- optimizeDeps,
141131 } ;
142132 } else if ( command === 'build' ) {
143133 //
@@ -164,13 +154,19 @@ export default defineConfig(({ command, mode }: ConfigEnv) => {
164154 main : 'src/main.tsx' ,
165155 } as Record < string , string > ,
166156 output : {
167- entryFileNames : '[name].js' ,
168- ...output ,
157+ entryFileNames : '[name].mjs' ,
158+ assetFileNames : ( assetInfo : PreRenderedAsset ) => {
159+ if ( assetInfo . name === 'main.css' ) {
160+ return '[name][extname]' ;
161+ }
162+ return '[name]-[hash][extname]' ;
163+ } ,
164+ inlineDynamicImports : false ,
165+ exports : 'named' as const ,
169166 } ,
170167 } ,
171168 } ,
172169 plugins,
173- optimizeDeps,
174170 } ;
175171 } else {
176172 return {
@@ -187,7 +183,7 @@ export default defineConfig(({ command, mode }: ConfigEnv) => {
187183 path . resolve ( __dirname , 'src/exports/hosted.ts' ) ,
188184 path . resolve ( __dirname , 'src/exports/executor.ts' ) ,
189185 ] ,
190- formats : ( isAnalyze ? [ 'es' ] : [ 'es' , 'cjs' ] ) as LibraryFormats [ ] ,
186+ formats : [ 'es' ] ,
191187 fileName : ( format , entryname ) => {
192188 const n = entryname . split ( '/' ) . pop ( ) ! ;
193189 return `${ n . split ( '.' ) [ 0 ] } .${ format === 'es' ? 'mjs' : 'js' } ` ;
@@ -201,7 +197,13 @@ export default defineConfig(({ command, mode }: ConfigEnv) => {
201197 hosted : 'src/exports/hosted.ts' ,
202198 executor : 'src/exports/executor.ts' ,
203199 } ,
204- output,
200+ output : {
201+ entryFileNames : '[name].mjs' ,
202+ chunkFileNames : '[name].mjs' ,
203+ assetFileNames : '[name].[ext]' ,
204+ inlineDynamicImports : false ,
205+ preserveModules : true ,
206+ } ,
205207 external : [
206208 'react' ,
207209 'react/jsx-runtime' ,
@@ -213,9 +215,14 @@ export default defineConfig(({ command, mode }: ConfigEnv) => {
213215 '@mui/system' ,
214216 ] ,
215217 } ,
218+ minify : false ,
219+ terserOptions : {
220+ mangle : false ,
221+ compress : false ,
222+ } ,
223+ sourcemap : true ,
216224 } ,
217225 plugins,
218- optimizeDeps,
219226 } ;
220227 }
221228 }
@@ -226,6 +233,5 @@ export default defineConfig(({ command, mode }: ConfigEnv) => {
226233 envPrefix,
227234 resolve,
228235 plugins,
229- optimizeDeps,
230236 } ;
231237} ) ;
0 commit comments