Vue webpack 打包時長統計
阿新 • • 發佈:2021-02-11
Vue webpack 打包時長統計
在package.json中發現build
實際呼叫的是vue-cli-service
"scripts": {
"dev": "vue-cli-service serve",
"build": "vue-cli-service build"
},
執行的函式是 node_modules/@vue/cli-service/lib/commands/build/index.js
中的build
//開始時間
let startTime = '';
//在構建函式中記錄開始時間
async function build (args, api, options) {
startTime = Date.parse(new Date())
console.log('開始時間戳:'+startTime)
/*
* ...
*/
return new Promise((resolve, reject) => {
webpack(webpackConfig, (err, stats) => {
//....
if (!args. watch) {
console.log('結束時間戳:'+Date.parse(new Date()))
console.log('花費時間:'+(Date.parse(new Date())-startTime)/1000+'秒')
done(`Build complete. The ${chalk.cyan(targetDirShort)} directory is ready to be deployed.`)
info(`Check out deployment instructions at ${ chalk.cyan(`https://cli.vuejs.org/guide/deployment.html`)}\n`)
} else {
done(`Build complete. Watching for changes...`)
}
}
}
//...
resolve()
})
})
}
重新執行npm run build
結果如下: