You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 6727922
Browse filesBrowse the repository at this point in the historyBrowse files
feat: minify JSON assets under futureDefaults (#22286)
* feat: minify JSON assets under futureDefaults
Add `optimization.minimizeOptions.json`, which dispatches JSON assets to
minimizer-webpack-plugin's `jsonMinify`. It defaults to `true` with
`experiments.futureDefaults` and steps aside for a user JSON minimizer.
* fix: keep JSON tokens exact and require both matchers to claim
Minify JSON assets with webpack's own whitespace-only jsonMinify so large
integers and exponents survive, and leave non-JSON .json assets as written.
A configured minimizer now claims a type only when its test and include
both match.
* test: cover jsonMinify directly
The default minimizer runs it in a worker, where integration cases do not
collect coverage, so exercise it the way jsMinify.unittest.js does.
* test: keep coverage instrumentation out of jsonMinify
The minimizer ships it to its worker pool as source, where the injected
coverage counters are undefined, like the other worker minifiers.
* test: check minimize-json assets from the config
futureDefaults emits an ESM bundle, which reaches fs through createRequire
and so fails on Node 10; read the emitted files in afterEmit instead.
* fix: match JSON asset names carrying a fragment
Use the same name pattern #22277 gave the JS, CSS and HTML minifiers, so
`data.json#hash` is minified too.
Copy file name to clipboardExpand all lines: AGENTS.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -84,7 +84,7 @@ This is the canonical repository map. **When you add, rename or remove a top-lev
84
84
-`syntax.js` reaches `parser` and `printer` through getters: parsing never loads the printer, printing never the parser.
85
85
-`syntax-parser.js` — tokenizer, acorn-derived core and every production in one file (any parse reaches the productions, and the coming struct-of-arrays rewrite moves node creation through them). `regexp.js` (pattern validator) is the one on-demand piece, reached only for a pattern the host engine rejected — never `require` it from a build path.
86
86
-`syntax-printer.js` — prints JS back out. `jsMinify.js` (the `minify` the default minimizer dispatches JS to) goes through it rather than terser's published entry, because that loader reads terser's sources — letting a phase webpack implements replace terser's method. Each phase taken over is one less thing terser does. A phase states what it reads with `supports`; a minifier that moved any of it, or a runtime that can't import those sources, keeps its own. Add phases to the `PHASES` list there and nowhere else, each writing byte-for-byte what it replaced.
87
-
-`lib/json/` — JSON modules.
87
+
-`lib/json/` — JSON modules, and `jsonMinify`, which strips the whitespace between a JSON asset's tokens for the default minimizer.
88
88
-`lib/library/` — UMD/AMD/ESM/CommonJS library formats, and the deprecated `LibraryTemplatePlugin` (old two-argument API).
89
89
-`lib/loaders/` — loader execution (vendored loader-runner): pitching/normal iteration and loader loading, plus `LoaderOptionsPlugin` and `LoaderTargetPlugin`, which feed the loader context.
90
90
-`lib/logging/` — Logger API, console formatting, and `ProgressPlugin` (reports through it). `lib/ProgressPlugin` stays a re-export (webpack-stream requires it).
MIT License http://www.opensource.org/licenses/mit-license.php
3
+
Author sheo13666q @sheo13666q
4
+
*/
5
+
6
+
"use strict";
7
+
8
+
/**
9
+
* A `minify` function for `minimizer-webpack-plugin` that drops the whitespace
10
+
* between a JSON asset's tokens and keeps every token as written. Source that is
11
+
* not valid JSON is returned unchanged rather than failing the build.
12
+
* @param {{ [file: string]: string | Buffer }} input a single `{ filename: code }` entry; a `Buffer` is read as UTF-8
13
+
* @returns {Promise<{ code: string }>} the minified JSON
14
+
*/
15
+
constjsonMinify=async(input)=>{
16
+
// WHY: the body is self-contained because the plugin ships this function to
17
+
// its worker pool as source. Re-serializing through `JSON.parse` would round
18
+
// `9007199254740993` to `…992` and turn `1e400` into `null`, so only the
19
+
// whitespace goes; `JSON.parse` is asked solely whether the source is JSON.
"description": "Minimize JSON assets by re-serializing them without whitespace (defaults to `true` with `experiments.futureDefaults`, otherwise `false`).",
Copy file name to clipboardExpand all lines: test/__snapshots__/Cli.basictest.js.snap
+26Lines changed: 26 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -11884,6 +11884,19 @@ Object {
11884
11884
"multiple": false,
11885
11885
"simpleType": "boolean",
11886
11886
},
11887
+
"optimization-minimize-json": Object {
11888
+
"configs": Array [
11889
+
Object {
11890
+
"description": "Minimize JSON assets by re-serializing them without whitespace (defaults to \`true\` with \`experiments.futureDefaults\`, otherwise \`false\`).",
11891
+
"multiple": false,
11892
+
"path": "optimization.minimize.json",
11893
+
"type": "boolean",
11894
+
},
11895
+
],
11896
+
"description": "Minimize JSON assets by re-serializing them without whitespace (defaults to \`true\` with \`experiments.futureDefaults\`, otherwise \`false\`).",
11897
+
"multiple": false,
11898
+
"simpleType": "boolean",
11899
+
},
11887
11900
"optimization-minimize-options-css": Object {
11888
11901
"configs": Array [
11889
11902
Object {
@@ -12575,6 +12588,19 @@ Object {
12575
12588
"multiple": false,
12576
12589
"simpleType": "boolean",
12577
12590
},
12591
+
"optimization-minimize-options-json": Object {
12592
+
"configs": Array [
12593
+
Object {
12594
+
"description": "Minimize JSON assets by re-serializing them without whitespace (defaults to \`true\` with \`experiments.futureDefaults\`, otherwise \`false\`).",
12595
+
"multiple": false,
12596
+
"path": "optimization.minimizeOptions.json",
12597
+
"type": "boolean",
12598
+
},
12599
+
],
12600
+
"description": "Minimize JSON assets by re-serializing them without whitespace (defaults to \`true\` with \`experiments.futureDefaults\`, otherwise \`false\`).",
0 commit comments