@@ -104,14 +104,22 @@ export function NuxtScriptBundleTransformer(options: AssetBundlerTransformerOpti
104
104
// done after all transformation is done
105
105
// copy all scripts to build
106
106
nuxt . hooks . hook ( 'build:done' , async ( ) => {
107
- logger . log ( '[nuxt:scripts:bundler-transformer] Bundling scripts...' )
108
- await fsp . rm ( cacheDir , { recursive : true , force : true } )
109
- await fsp . mkdir ( cacheDir , { recursive : true } )
110
- await Promise . all ( [ ...renderedScript ] . map ( async ( [ url , content ] ) => {
107
+ const scripts = [ ...renderedScript ]
108
+ if ( ! scripts . length ) {
109
+ logger . debug ( '[bundle-script-transformer] No scripts to bundle...' )
110
+ return
111
+ }
112
+ logger . info ( '[bundle-script-transformer] Bundling scripts...' )
113
+ // less aggressive cache clearing in dev
114
+ if ( ! nuxt . options . dev ) {
115
+ await fsp . rm ( cacheDir , { recursive : true , force : true } )
116
+ await fsp . mkdir ( cacheDir , { recursive : true } )
117
+ }
118
+ await Promise . all ( scripts . map ( async ( [ url , content ] ) => {
111
119
if ( content instanceof Error || ! content . filename )
112
120
return
113
121
await fsp . writeFile ( join ( nuxt . options . buildDir , 'cache' , 'scripts' , content . filename ) , content . content )
114
- logger . log ( colors . gray ( ` ├─ ${ url } → ${ joinURL ( content . src ) } (${ content . size . toFixed ( 2 ) } kB ${ content . encoding } )` ) )
122
+ logger . info ( colors . gray ( ` ├─ ${ url } → ${ joinURL ( content . src ) } (${ content . size . toFixed ( 2 ) } kB ${ content . encoding } )` ) )
115
123
} ) )
116
124
} )
117
125
0 commit comments