Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions scripts/rollup/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,11 +470,10 @@ function getPlugins(
// I'm going to port "art" to ES modules to avoid this problem.
// Please don't enable this for anything else!
isUMDBundle && entry === 'react-art' && commonjs(),
// License and haste headers, top-level `if` blocks.
{
name: 'license-and-headers',
name: 'top-level-definitions',
renderChunk(source) {
return Wrappers.wrapBundle(
return Wrappers.wrapWithTopLevelDefinitions(
source,
bundleType,
globalName,
Expand All @@ -484,6 +483,21 @@ function getPlugins(
);
},
},
// License and haste headers for artifacts with sourcemaps
// For artifacts with sourcemaps we apply these headers
// before passing sources to the Closure compiler, which will be building sourcemaps
needsSourcemaps && {
name: 'license-and-signature-header-for-artifacts-with-sourcemaps',
renderChunk(source) {
return Wrappers.wrapWithLicenseHeader(
source,
bundleType,
globalName,
filename,
moduleType
);
},
},
// Apply dead code elimination and/or minification.
// closure doesn't yet support leaving ESM imports intact
needsMinifiedByClosure &&
Expand Down Expand Up @@ -527,7 +541,7 @@ function getPlugins(
}),
needsSourcemaps && {
name: 'generate-prod-bundle-sourcemaps',
async renderChunk(codeAfterLicense, chunk, options, meta) {
async renderChunk(minifiedCodeWithChangedHeader, chunk, options, meta) {
// We want to generate a sourcemap that shows the production bundle source
// as it existed before Closure Compiler minified that chunk, rather than
// showing the "original" individual source files. This better shows
Expand Down Expand Up @@ -583,7 +597,7 @@ function getPlugins(

// Add the sourcemap URL to the actual bundle, so that tools pick it up
const sourceWithMappingUrl =
codeAfterLicense +
minifiedCodeWithChangedHeader +
`\n//# sourceMappingURL=${finalSourcemapFilename}`;

return {
Expand All @@ -592,6 +606,21 @@ function getPlugins(
};
},
},
// License and haste headers for artifacts without sourcemaps
// Primarily used for FB-artifacts, which should preserve specific format of the header
// Which potentially can be changed by Closure minification
!needsSourcemaps && {
name: 'license-and-signature-header-for-artifacts-without-sourcemaps',
renderChunk(source) {
return Wrappers.wrapWithLicenseHeader(
source,
bundleType,
globalName,
filename,
moduleType
);
},
},
// Record bundle size.
sizes({
getSize: (size, gzip) => {
Expand Down
Loading