Skip to content

Commit b10c20a

Browse files
committed
Merge branch 'feat/issue-120-sourcemap-target' into 'edge'
esbuild: pin the browser target, and keep sourcemaps out of production (hyperstack-org#120) Closes hyperstack-org#120 See merge request ru/hyperstack!161
2 parents 7e8a091 + c2bff44 commit b10c20a

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

  • ruby/rails-hyperstack/lib/generators/hyperstack/js_pipeline/templates

‎ruby/rails-hyperstack/lib/generators/hyperstack/js_pipeline/templates/esbuild.config.js‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ require('esbuild').build({
2020
],
2121
bundle: true,
2222
outdir: 'app/assets/builds',
23+
// Declare the browser baseline instead of inheriting it (#120). Unset, esbuild
24+
// defaults to `esnext` and downlevels NOTHING, so "which browsers does this app
25+
// support?" was answered by whichever esbuild version happened to be in
26+
// package.json -- and an esbuild upgrade could move it silently.
27+
//
28+
// es2020 is Chrome 80 / Safari 13.1 / Firefox 72, all 2020 or earlier, and
29+
// comfortably below what React 18/19 already require, so pinning it costs
30+
// nothing today. It is a floor, not a ceiling: an app that needs a different
31+
// baseline edits this file, which is generated into the app and owned by it.
32+
target: ['es2020'],
2333
define: { 'process.env.NODE_ENV': JSON.stringify(nodeEnv) },
2434
// Without this the bundle shipped unminified -- 1.2 MB, which esbuild itself
2535
// flags. `define` above already selects React's production code, so this is
@@ -30,6 +40,19 @@ require('esbuild').build({
3040
//
3141
// NODE_ENV=development skips it, for anyone who needs to read the bundle.
3242
minify: nodeEnv === 'production',
43+
// Same signal, pointing the same way: a development build is minify-off and
44+
// mapped-on, a production build is minify-on and mapped-off. (#120)
45+
//
46+
// Production maps are deliberately NOT emitted. They only earn their place
47+
// when something CONSUMES them -- an error tracker ingesting maps privately to
48+
// symbolicate traces. A generated app has no such integration, so publishing
49+
// them would just serve the original module structure that minifying above
50+
// removed, at a guessable path. An app that does run a tracker turns this on
51+
// in its own copy of this file.
52+
//
53+
// 'inline' would be actively wrong here: the map is typically larger than the
54+
// minified code it describes, which would undo most of #107.
55+
sourcemap: nodeEnv !== 'production',
3356
// `keepNames` was tried here and removed. It preserves `Function.prototype.name`,
3457
// which is NOT what React >= 17 error frames report -- they name the JavaScript
3558
// function as the engine sees it, so the frames stayed minified (`at b` became

0 commit comments

Comments
 (0)