• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mozilla / blurts-server / 44eaccd4-a9c0-4630-a681-95835812ef01

pending completion
44eaccd4-a9c0-4630-a681-95835812ef01

Pull #3003

circleci

Vincent
fixup! Proposal: caching static generated assets
Pull Request #3003: Proposal: caching static generated assets

282 of 1774 branches covered (15.9%)

Branch coverage included in aggregate %.

13 of 13 new or added lines in 2 files covered. (100.0%)

959 of 4681 relevant lines covered (20.49%)

3.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/esbuild.js
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4

5
// TODO: this is a build/config file and should probably live in the root, after the old esbuild.js file is removed.
6

7
// ESBuild is used to concat and compress the 'client' folder into the 'dist' folder (front-end only)
8

9
import esbuild from 'esbuild'
10
import { readdirSync } from 'node:fs'
11
import { writeFile } from 'node:fs/promises'
12
import AppConstants from './appConstants.js'
13

14
const cssPartialDir = 'client/css/partials/'
×
15
const cssPartialPaths = readdirSync(cssPartialDir, { withFileTypes: true })
×
16
  .filter(dirent => dirent.isFile())
×
17
  .map(dirent => cssPartialDir + dirent.name)
×
18

19
const jsPartialDir = 'client/js/partials/'
×
20
const jsPartialPaths = readdirSync(jsPartialDir, { withFileTypes: true })
×
21
  .filter(dirent => dirent.isFile())
×
22
  .map(dirent => jsPartialDir + dirent.name)
×
23

24
const buildResult = await esbuild.build({
×
25
  logLevel: 'info',
26
  bundle: true,
27
  entryPoints: ['client/js/index.js', 'client/css/index.css', ...cssPartialPaths, ...jsPartialPaths],
28
  entryNames: '[dir]/[name]-[hash].hashed',
29
  loader: { '.woff2': 'copy' },
30
  assetNames: '[dir]/[name]-[hash].hashed',
31
  external: ['*.webp', '*.svg'],
32
  outdir: '../dist',
33
  format: 'esm',
34
  metafile: true,
35
  minify: AppConstants.NODE_ENV !== 'dev',
36
  sourcemap: AppConstants.NODE_ENV !== 'dev',
37
  splitting: false, // see note below
38
  treeShaking: true,
39
  platform: 'neutral',
40
  define: {
41
    buildConstants: JSON.stringify({
42
      NODE_ENV: AppConstants.NODE_ENV,
43
      GA4_MEASUREMENT_ID: AppConstants.GA4_MEASUREMENT_ID
44
    })
45
  }
46
})
47

48
function getPathMap (meta) {
49
  /** @type {Record<string, string>} */
50
  const assetPathMap = {}
×
51

52
  Object.entries(meta.outputs).forEach(([outputPath, outputMeta]) => {
×
53
    if (outputMeta.entryPoint) {
×
54
      assetPathMap[outputMeta.entryPoint] = outputPath
×
55
    } else {
56
      const [onlyInput] = Object.keys(outputMeta.inputs)
×
57
      if (onlyInput) {
×
58
        assetPathMap[onlyInput] = outputPath
×
59
      }
60
    }
61
  })
62

63
  return assetPathMap
×
64
}
65

66
writeFile('../dist/meta.json', JSON.stringify(getPathMap(buildResult.metafile)))
×
67

68
/*
69
ESBuild automatic code-splitting is disabled for the following reasons:
70
- As of this writing, ESBuild code-splitting is suggested to be experimental/WIP: https://esbuild.github.io/api/#splitting
71
- There is a known bug with ESBuild that loads chunks out of order: https://github.com/evanw/esbuild/issues/399
72
- The complete client bundle is currently only ~10kB transferred; splitting this down further is unlikely to result in significant load speed gains
73
- A ticket exists (MNTOR-1171) to set up logical code-splitting depending on partial. Once complete, the conflict/redundancy with ESBuild code-splitting will increase
74
- see also https://github.com/mozilla/blurts-server/pull/2844
75
*/
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc