From 3abefdcb39128e62e3e15e1c96f23ff308fcfca9 Mon Sep 17 00:00:00 2001 From: Adam Skoufis Date: Thu, 11 Jul 2024 11:49:46 +1000 Subject: [PATCH] sku v13: Set `sourceMapsProd` default value to `true` (#979) --- .changeset/many-deers-check.md | 26 +++++++++++++++++ docs/docs/configuration.md | 23 +++++++++++++-- docs/docs/extra-features.md | 4 +-- packages/sku/context/defaultSkuConfig.js | 2 +- packages/sku/sku-types.d.ts | 4 ++- .../braid-design-system.test.js.snap | 15 ++++++---- .../custom-src-paths.test.ts.snap | 3 ++ .../__snapshots__/library-build.test.js.snap | 6 ++++ tests/__snapshots__/library-file.test.js.snap | 6 ++++ .../multiple-routes.test.js.snap | 28 +++++++++++++------ tests/__snapshots__/public-path.test.js.snap | 2 +- .../__snapshots__/sku-with-https.test.js.snap | 2 +- .../ssr-hello-world.test.js.snap | 4 +-- tests/__snapshots__/styling.test.ts.snap | 12 ++++++-- .../typescript-css-modules.test.ts.snap | 18 ++++++++---- 15 files changed, 123 insertions(+), 32 deletions(-) create mode 100644 .changeset/many-deers-check.md diff --git a/.changeset/many-deers-check.md b/.changeset/many-deers-check.md new file mode 100644 index 000000000..2ba108013 --- /dev/null +++ b/.changeset/many-deers-check.md @@ -0,0 +1,26 @@ +--- +'sku': major +--- + +`sourceMapsProd` is now `true` by default + +**BREAKING CHANGE**: + +`sourceMapsProd` is now `true` by default. To enable the previous behaviour, set `sourceMapsProd: false` in your sku config: + +```ts +// sku.config.ts +import type { SkuConfig } from 'sku'; + +export default { + sourceMapsProd: false, +} satisfies SkuConfig; +``` + +**NOTE**: Production source maps can increase memory usage during builds to the point where the Node process exhausts its heap memory. If this occurs, you can increase the memory limit for the Node process by setting the `NODE_OPTIONS` environment variable to `--max-old-space-size=4096` (or a higher value) before running the build command. + +For example: + +```sh +NODE_OPTIONS=--max-old-space-size=4096 sku build +``` diff --git a/docs/docs/configuration.md b/docs/docs/configuration.md index 5bc57050e..691a09c0c 100644 --- a/docs/docs/configuration.md +++ b/docs/docs/configuration.md @@ -396,17 +396,34 @@ const config = { type `boolean` -By default source maps will be generated only for development builds. -Set to `true` to enable source maps in production. +Default: `true` + +Source maps are always generated for development builds. +It is recommended to enable source maps for production builds in order to aid debugging. +To disable source maps for production builds, set this option to `false`. Example: ```ts export default { - sourceMapsProd: true, + sourceMapsProd: false, } satisfies SkuConfig; ``` +**NOTE**: Production source maps can increase memory usage during builds to the point where the Node process exhausts its heap memory. +If this occurs, you can increase the memory limit for the Node process by setting the `NODE_OPTIONS` environment variable to `--max-old-space-size=4096` (or a higher value) before running the build command. + +For example: + +```sh +NODE_OPTIONS=--max-old-space-size=4096 sku build +``` + +### When to disable `sourceMapsProd` + +Production source maps can be expensive. +If your application does not utilize production source maps, e.g. you have no tracking of production errors, you can disable them to potentially reduce build times and memory usage. + ## srcPaths type `Array` diff --git a/docs/docs/extra-features.md b/docs/docs/extra-features.md index b6ed44591..2d96d0d08 100644 --- a/docs/docs/extra-features.md +++ b/docs/docs/extra-features.md @@ -9,8 +9,8 @@ If you want to use a currently unsupported format feel free to submit a PR or co ## Source maps -Source maps are enabled by default when running the `sku start` command. -However, if you want to generate source maps when running `sku build`, you can do so by enabling [`sourceMapsProd`](./docs/configuration#sourcemapsprod). +Source maps are enabled by default when running both `sku start` and `sku build`. +If you want to disable source map generation for production builds, you can set [`sourceMapsProd`](./docs/configuration#sourcemapsprod) to `false`. ## Compile packages diff --git a/packages/sku/context/defaultSkuConfig.js b/packages/sku/context/defaultSkuConfig.js index 63317ff25..20c52ecdc 100644 --- a/packages/sku/context/defaultSkuConfig.js +++ b/packages/sku/context/defaultSkuConfig.js @@ -32,7 +32,7 @@ module.exports = { polyfills: [], libraryName: null, libraryFile: null, - sourceMapsProd: false, + sourceMapsProd: true, displayNamesProd: false, dangerouslySetWebpackConfig: defaultDecorator, dangerouslySetJestConfig: defaultDecorator, diff --git a/packages/sku/sku-types.d.ts b/packages/sku/sku-types.d.ts index 4bea5f5db..7f9a2fe83 100644 --- a/packages/sku/sku-types.d.ts +++ b/packages/sku/sku-types.d.ts @@ -381,8 +381,10 @@ export interface SkuConfig { skipPackageCompatibilityCompilation?: string[]; /** - * By default source maps will be generated only for development builds. Set to `true` to enable source maps in production. + * Source maps are always generated for development builds. + * To disable source maps for production builds, set this option to `false`. * + * @default true * @link https://seek-oss.github.io/sku/#/./docs/configuration?id=sourcemapsprod */ sourceMapsProd?: boolean; diff --git a/tests/__snapshots__/braid-design-system.test.js.snap b/tests/__snapshots__/braid-design-system.test.js.snap index 9976aab1d..f7ec06c7e 100644 --- a/tests/__snapshots__/braid-design-system.test.js.snap +++ b/tests/__snapshots__/braid-design-system.test.js.snap @@ -2,7 +2,7 @@ exports[`braid-design-system build should generate the expected files 1`] = ` { - "2-07fafa59b5872fc8269f.css": ._1toce6t0 { + "2-057ed479da430777bc0c.css": ._1toce6t0 { border: 0; box-sizing: border-box; font-size: 100%; @@ -3100,7 +3100,10 @@ html:not(._19jnx86z) .ad2p4ma { 0 12px 12px -4px rgba(28, 35, 48, 0.1), 0 20px 20px -12px rgba(28, 35, 48, 0.2); } + +/*# sourceMappingURL=2-057ed479da430777bc0c.css.map*/ , + "2-057ed479da430777bc0c.css.map": "CONTENTS IGNORED IN SNAPSHOT TEST", "externals.json": "[ "crypto", "fs", @@ -3119,7 +3122,7 @@ html:not(._19jnx86z) .ad2p4ma { My Awesome Project - + , - "main-1a83a1ba0e49241a7187.css": .external { + "main-f11c7eb5d7d4b8c58e2e.css": .external { display: none; font-size: 9px; } @@ -223,9 +224,14 @@ SOURCE HTML: height: 100px; width: 100px; } + +/*# sourceMappingURL=main-f11c7eb5d7d4b8c58e2e.css.map*/ , + "main-f11c7eb5d7d4b8c58e2e.css.map": "CONTENTS IGNORED IN SNAPSHOT TEST", "main.js": "CONTENTS IGNORED IN SNAPSHOT TEST", + "main.js.map": "CONTENTS IGNORED IN SNAPSHOT TEST", "runtime.js": "CONTENTS IGNORED IN SNAPSHOT TEST", + "runtime.js.map": "CONTENTS IGNORED IN SNAPSHOT TEST", } `; diff --git a/tests/__snapshots__/typescript-css-modules.test.ts.snap b/tests/__snapshots__/typescript-css-modules.test.ts.snap index c12fa4ba9..0f3cd09c4 100644 --- a/tests/__snapshots__/typescript-css-modules.test.ts.snap +++ b/tests/__snapshots__/typescript-css-modules.test.ts.snap @@ -7,7 +7,7 @@ SCRIPTS: [ "/static/typescript/main.js", ] CSS: [ - "/static/typescript/main-cb5c558f16bd36d80f00.css", + "/static/typescript/main-4bad37555f2de4beeb21.css", ] SOURCE HTML: @@ -106,13 +106,14 @@ POST HYDRATE DIFFS: exports[`typescript-css-modules build should generate the expected files 1`] = ` { "2.js": "CONTENTS IGNORED IN SNAPSHOT TEST", + "2.js.map": "CONTENTS IGNORED IN SNAPSHOT TEST", "index.html": SCRIPTS: [ "/static/typescript/runtime.js", "/static/typescript/2.js", "/static/typescript/main.js", ] CSS: [ - "/static/typescript/main-cb5c558f16bd36d80f00.css", + "/static/typescript/main-4bad37555f2de4beeb21.css", ] SOURCE HTML: @@ -196,15 +197,20 @@ SOURCE HTML: , - "main-cb5c558f16bd36d80f00.css": ._19hsk3y0 { + "main-4bad37555f2de4beeb21.css": ._19hsk3y0 { display: flex; } ._19hsk3y0 ._19hsk3y1 { font-size: 32px; } + +/*# sourceMappingURL=main-4bad37555f2de4beeb21.css.map*/ , + "main-4bad37555f2de4beeb21.css.map": "CONTENTS IGNORED IN SNAPSHOT TEST", "main.js": "CONTENTS IGNORED IN SNAPSHOT TEST", + "main.js.map": "CONTENTS IGNORED IN SNAPSHOT TEST", "runtime.js": "CONTENTS IGNORED IN SNAPSHOT TEST", + "runtime.js.map": "CONTENTS IGNORED IN SNAPSHOT TEST", } `; @@ -215,7 +221,7 @@ SCRIPTS: [ "http://localhost:4003/main.js", ] CSS: [ - "http://localhost:4003/main-cb5c558f16bd36d80f00.css", + "http://localhost:4003/main-4bad37555f2de4beeb21.css", ] SOURCE HTML: @@ -322,12 +328,14 @@ POST HYDRATE DIFFS: exports[`typescript-css-modules build-ssr should generate the expected files 1`] = ` { "2.js": "CONTENTS IGNORED IN SNAPSHOT TEST", - "main-cb5c558f16bd36d80f00.css": ._19hsk3y0 { + "main-4bad37555f2de4beeb21.css": ._19hsk3y0 { display: flex; } ._19hsk3y0 ._19hsk3y1 { font-size: 32px; } + +/*# sourceMappingURL=main-4bad37555f2de4beeb21.css.map*/ , "main.js": "CONTENTS IGNORED IN SNAPSHOT TEST", "runtime.js": "CONTENTS IGNORED IN SNAPSHOT TEST",