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 459a017
Browse filesBrowse the repository at this point in the historyBrowse files
feat(library): add library.entryExports to expose every entry module (#22235)
* feat(library): add library.entryExports to expose every entry module
An entry with several modules exports only the last one's, so a library
build silently drops the rest and tree shaking removes them in production
(#15936). Making that the default would break a contract webpack has kept
since 4, so `entryExports` names it `last` and takes `all` to opt in — on
`output.library` and on `entry.<name>.library` alike, since an
application's entry exports nothing anyone reads.
The merged object is written out at compile time as a
`__webpack_require__.d` call over the entry modules' known exports, so
every name stays visible to an analyzer and no runtime helper is needed.
Conflicts follow ES modules: a name more than one module binds
differently is left out with a warning, while one they all take from the
same binding survives. An entry providing unknown exports, or an async
one this output can't await, is an error rather than a thinner library.
* fix(library): keep one default export when merging a CommonJS entry
A CommonJS entry module adds `export default __webpack_exports__` to a
`module` library so it stays importable, and that decision read the last
entry module alone. With `entryExports: "all"` an earlier ES module can
still export a real `default`, so the bundle carried both and no engine
would load it. The synthetic one is now emitted only when every merged
module is CommonJS — the same condition that already decided whether to
drop `default` from the export clause, and unchanged for a single entry.
* test(library): read the commonjs-static exports without matchAll
`String.prototype.matchAll` is newer than the Node baseline the harness
executes a case under, so the assertion threw on the Node 10 job while
passing everywhere else. An `exec` loop reads the same names.
MIT License http://www.opensource.org/licenses/mit-license.php
3
+
Author Alexander Akait @alexander-akait
4
+
*/
5
+
6
+
"use strict";
7
+
8
+
constWebpackError=require("./WebpackError");
9
+
10
+
/** @import Chunk from "../graph/Chunk" */
11
+
12
+
/**
13
+
* Warning raised when several modules of an `entryExports: "all"` entry bind the same
14
+
* export name, which leaves the name out of the merged exports.
MIT License http://www.opensource.org/licenses/mit-license.php
3
+
Author Alexander Akait @alexander-akait
4
+
*/
5
+
6
+
"use strict";
7
+
8
+
constWebpackError=require("./WebpackError");
9
+
10
+
/** @import Chunk from "../graph/Chunk" */
11
+
12
+
/**
13
+
* Error raised when an entry asks for `entryExports: "all"` but webpack cannot build
* Captures the chunk carrying the entry and why its exports cannot be merged.
19
+
* @param {Chunk} chunk the chunk carrying the entry
20
+
* @param {string} reason what stands in the way, as a sentence fragment
21
+
*/
22
+
constructor(chunk,reason){
23
+
super(
24
+
`Entry "${chunk.name||chunk.id}" can't merge the exports of its modules because ${reason}. Set 'library.entryExports' back to 'last', or re-export the modules from a single entry module instead.`
0 commit comments