mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-14 10:04:05 +00:00
parent
8b5e52f2a9
commit
9f506ded60
@ -17,15 +17,26 @@ const logEnd = id => { const t = end(_s[id]); delete _s[id]; metrics.push([id, t
|
|||||||
${TIMING} = { start, end, metrics, logStart, logEnd };
|
${TIMING} = { start, end, metrics, logStart, logEnd };
|
||||||
`)
|
`)
|
||||||
|
|
||||||
|
const HELPERIMPORT = "import './timing.js';"
|
||||||
|
|
||||||
export function timing (_opts: Options = {}): Plugin {
|
export function timing (_opts: Options = {}): Plugin {
|
||||||
return {
|
return {
|
||||||
name: 'timing',
|
name: 'timing',
|
||||||
|
generateBundle () {
|
||||||
|
this.emitFile({
|
||||||
|
type: 'asset',
|
||||||
|
fileName: 'timing.js',
|
||||||
|
source: HELPER
|
||||||
|
})
|
||||||
|
},
|
||||||
renderChunk (code, chunk: RenderedChunk) {
|
renderChunk (code, chunk: RenderedChunk) {
|
||||||
let name = chunk.fileName || ''
|
let name = chunk.fileName || ''
|
||||||
name = name.replace(extname(name), '')
|
name = name.replace(extname(name), '')
|
||||||
|
|
||||||
const logName = name === 'index' ? 'Cold Start' : ('Load ' + name)
|
const logName = name === 'index' ? 'Cold Start' : ('Load ' + name)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
code: (chunk.isEntry ? HELPER : '') + `${TIMING}.logStart('${logName}');` + code + `;${TIMING}.logEnd('${logName}');`,
|
code: (chunk.isEntry ? HELPERIMPORT : '') + `${TIMING}.logStart('${logName}');` + code + `;${TIMING}.logEnd('${logName}');`,
|
||||||
map: null
|
map: null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user