code.cjs 873 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. const fs = require('node:fs')
  2. const path = require('node:path')
  3. const rootDir = path.resolve(__dirname, '..', '..')
  4. const distDir = path.join(rootDir, 'dist')
  5. function readManifest() {
  6. const manifestPath = path.join(distDir, '.vite', 'manifest.json')
  7. if (!fs.existsSync(manifestPath)) {
  8. return {}
  9. }
  10. return JSON.parse(fs.readFileSync(manifestPath, 'utf8'))
  11. }
  12. function pickAssets(manifest) {
  13. return Object.entries(manifest)
  14. .filter(([, entry]) => entry.isEntry || entry.file.endsWith('.css'))
  15. .map(([source, entry]) => ({
  16. source,
  17. file: entry.file,
  18. css: entry.css || []
  19. }))
  20. }
  21. module.exports = {
  22. rootDir,
  23. distDir,
  24. readManifest,
  25. pickAssets,
  26. createReport() {
  27. const assets = pickAssets(readManifest())
  28. return {
  29. generatedAt: new Date().toISOString(),
  30. assetCount: assets.length,
  31. assets
  32. }
  33. }
  34. }