mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
build: no longer add pure annotations to es5 bundles (#6107)
* The pure annotations are no longer added to ES5 bundles of Angular Material or the CDK. The pure annotations should be added by the new build optimizer which is part of the CLI.
This commit is contained in:
committed by
tinayuangao
parent
e79f7f9c77
commit
2320532516
@@ -1,7 +1,6 @@
|
||||
import {join} from 'path';
|
||||
import {mkdirpSync} from 'fs-extra';
|
||||
import {copyFiles} from './copy-files';
|
||||
import {addPureAnnotationsToFile} from './pure-annotations';
|
||||
import {replaceVersionPlaceholders} from './version-placeholders';
|
||||
import {inlinePackageMetadataFiles} from './metadata-inlining';
|
||||
import {createTypingsReexportFile} from './typings-reexport';
|
||||
@@ -43,8 +42,6 @@ export function composeRelease(packageName: string, options: ComposeReleaseOptio
|
||||
if (options.useSecondaryEntryPoints) {
|
||||
createFilesForSecondaryEntryPoint(packageName, packagePath, releasePath);
|
||||
}
|
||||
|
||||
addPureAnnotationsToFile(join(releasePath, '@angular', `${packageName}.es5.js`));
|
||||
}
|
||||
|
||||
/** Creates files necessary for a secondary entry-point. */
|
||||
|
||||
@@ -5,7 +5,7 @@ import {join, dirname} from 'path';
|
||||
/** Function to copy files that match a glob to another directory. */
|
||||
export function copyFiles(fromPath: string, fileGlob: string, outDir: string) {
|
||||
glob(fileGlob, {cwd: fromPath}).forEach(filePath => {
|
||||
let fileDestPath = join(outDir, filePath);
|
||||
const fileDestPath = join(outDir, filePath);
|
||||
mkdirpSync(dirname(fileDestPath));
|
||||
copySync(join(fromPath, filePath), fileDestPath);
|
||||
});
|
||||
|
||||
@@ -12,5 +12,5 @@ export function createEntryPointPackageJson(destDir: string, packageName: string
|
||||
es2015: `../@angular/${packageName}/${entryPointName}.js`,
|
||||
};
|
||||
|
||||
writeFileSync(join(destDir, 'package.json'), JSON.stringify(content), 'utf-8');
|
||||
writeFileSync(join(destDir, 'package.json'), JSON.stringify(content, null, 2), 'utf-8');
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ import {join} from 'path';
|
||||
|
||||
/** Creates a metadata file that re-exports the metadata bundle inside of the typings. */
|
||||
export function createMetadataReexportFile(destDir: string, from: string, name: string) {
|
||||
const metadataReExport = `{
|
||||
"__symbolic":"module",
|
||||
"version":3,"metadata":{},
|
||||
"exports":[{"from":"${from}"}],
|
||||
"flatModuleIndexRedirect": true
|
||||
}`;
|
||||
writeFileSync(join(destDir, `${name}.metadata.json`), metadataReExport, 'utf-8');
|
||||
const metadataJsonContent = JSON.stringify({
|
||||
__symbolic: 'module',
|
||||
version: 3,
|
||||
metadata: {},
|
||||
exports: [{from}],
|
||||
flatModuleIndexRedirect: true
|
||||
}, null, 2);
|
||||
|
||||
writeFileSync(join(destDir, `${name}.metadata.json`), metadataJsonContent, 'utf-8');
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
import {readFileSync, writeFileSync} from 'fs';
|
||||
|
||||
/** Regex that matches downleveled class IIFE expressions. Used to add the pure annotations. */
|
||||
const classIfeeRegex =
|
||||
new RegExp('^(var (\\S+) = )(\\(function \\(\\) \\{[\\n\\r]*(?: (?:\\/\\*\\*| \\*|\\*\\/|' +
|
||||
'\\/\\/)[^\\n\\r]*[\\n\\r]*)* function \\2\\([^\\)]*\\) \\{[\\n\\r]*)', 'mg');
|
||||
|
||||
/** Regex that matches downleveled class IIFE expressions with _extends statements */
|
||||
const classExtendsIfeeRegex =
|
||||
/^(var (\S+) = )(\(function \(_super\) {[\n\r]* tslib.*\.__extends\(\2, _super\);[\n\r]*)/gm;
|
||||
|
||||
/**
|
||||
* Adds `@__PURE__` annotation comments to IIFEs containing ES5-downleveled classes generated by
|
||||
* TypeScript so that Uglify can tree-shake classes that are not referenced.
|
||||
*
|
||||
* @param fileContent The content of the file for which `@__PURE__` will be added.
|
||||
* @returns The content of the file with `@__PURE__` annotations added.
|
||||
*/
|
||||
export function addPureAnnotations(fileContent: string) {
|
||||
return fileContent
|
||||
// Prefix downleveled classes w/ the @__PURE__ annotation.
|
||||
.replace(classIfeeRegex, '$1/*@__PURE__*/$3')
|
||||
// Prefix downleveled classes that extend another class w/ the @__PURE__ annotation
|
||||
.replace(classExtendsIfeeRegex, '$1/*@__PURE__*/$3');
|
||||
}
|
||||
|
||||
/** Adds Uglify "@__PURE__" decorations to the specified file. */
|
||||
export function addPureAnnotationsToFile(inputFile: string) {
|
||||
const originalContent = readFileSync(inputFile, 'utf-8');
|
||||
const annotatedContent = addPureAnnotations(originalContent);
|
||||
|
||||
writeFileSync(inputFile, annotatedContent, 'utf-8');
|
||||
}
|
||||
Reference in New Issue
Block a user