@@ -12,7 +12,7 @@ import { join } from 'pathe'
12
12
import { colors } from 'consola/utils'
13
13
import { tryUseNuxt , useNuxt } from '@nuxt/kit'
14
14
import { logger } from '../logger'
15
- import { storage } from '../assets'
15
+ import { bundleStorage } from '../assets'
16
16
import { isJS , isVue } from './util'
17
17
import type { RegistryScript } from '#nuxt-scripts'
18
18
@@ -55,12 +55,13 @@ async function downloadScript(opts: {
55
55
if ( src === url || ! filename ) {
56
56
return
57
57
}
58
+ const storage = bundleStorage ( )
58
59
const scriptContent = renderedScript . get ( src )
59
60
let res : Buffer | undefined = scriptContent instanceof Error ? undefined : scriptContent ?. content
60
61
if ( ! res ) {
61
62
// Use storage to cache the font data between builds
62
- if ( await storage . hasItem ( `data:scripts :${ filename } ` ) ) {
63
- const res = await storage . getItemRaw < Buffer > ( `data:scripts :${ filename } ` )
63
+ if ( await storage . hasItem ( `bundle :${ filename } ` ) ) {
64
+ const res = await storage . getItemRaw < Buffer > ( `bundle :${ filename } ` )
64
65
renderedScript . set ( url , {
65
66
content : res ! ,
66
67
size : res ! . length / 1024 ,
@@ -80,11 +81,12 @@ async function downloadScript(opts: {
80
81
encoding = r . headers . get ( 'content-encoding' )
81
82
const contentLength = r . headers . get ( 'content-length' )
82
83
size = contentLength ? Number ( contentLength ) / 1024 : 0
83
-
84
84
return r . arrayBuffer ( )
85
85
} ) . then ( r => Buffer . from ( r ) )
86
86
87
- storage . setItemRaw ( `data:scripts:${ filename } ` , res )
87
+ await storage . setItemRaw ( `bundle:${ filename } ` , res )
88
+ size = size || res ! . length / 1024
89
+ logger . info ( `Downloading script ${ colors . gray ( `${ src } → ${ filename } (${ size . toFixed ( 2 ) } kB ${ encoding } )` ) } ` )
88
90
renderedScript . set ( url , {
89
91
content : res ! ,
90
92
size,
@@ -110,7 +112,7 @@ export function NuxtScriptBundleTransformer(options: AssetBundlerTransformerOpti
110
112
logger . debug ( '[bundle-script-transformer] No scripts to bundle...' )
111
113
return
112
114
}
113
- logger . info ( '[bundle-script-transformer] Bundling scripts...' )
115
+ logger . debug ( '[bundle-script-transformer] Bundling scripts...' )
114
116
// less aggressive cache clearing in dev
115
117
if ( ! nuxt . options . dev ) {
116
118
await fsp . rm ( cacheDir , { recursive : true , force : true } )
@@ -121,7 +123,7 @@ export function NuxtScriptBundleTransformer(options: AssetBundlerTransformerOpti
121
123
if ( content instanceof Error || ! content . filename )
122
124
return
123
125
await fsp . writeFile ( join ( nuxt . options . buildDir , 'cache' , 'scripts' , content . filename ) , content . content )
124
- logger . info ( colors . gray ( ` ├─ ${ url } → ${ joinURL ( content . src ) } (${ content . size . toFixed ( 2 ) } kB ${ content . encoding } )` ) )
126
+ logger . debug ( colors . gray ( ` ├─ ${ url } → ${ joinURL ( content . src ) } (${ content . size . toFixed ( 2 ) } kB ${ content . encoding } )` ) )
125
127
} ) )
126
128
} )
127
129
0 commit comments