1- import { extname , join } from 'path' ;
1+ import { extname } from 'path' ;
2+
3+ import * as MagicString from 'magic-string' ;
4+
25import { Logger } from './logger/logger' ;
36import { fillConfigDefaults , getUserConfigFile , replacePathVars } from './util/config' ;
47import * as Constants from './util/constants' ;
58import { BuildError } from './util/errors' ;
6- import { getBooleanPropertyValue , webpackStatsToDependencyMap , printDependencyMap } from './util/helpers' ;
9+ import { getBooleanPropertyValue , getStringPropertyValue , webpackStatsToDependencyMap , printDependencyMap } from './util/helpers' ;
710import { BuildContext , TaskInfo } from './util/interfaces' ;
811import { runWebpackFullBuild , WebpackConfig } from './webpack' ;
9- import { purgeDecorators } from './optimization/decorators' ;
12+ import { purgeStaticFieldDecorators } from './optimization/decorators' ;
1013import { getAppModuleNgFactoryPath , calculateUnusedComponents , purgeUnusedImportsAndExportsFromIndex , purgeComponentNgFactoryImportAndUsage , purgeProviderControllerImportAndUsage , purgeProviderClassNameFromIonicModuleForRoot } from './optimization/treeshake' ;
1114
1215export function optimization ( context : BuildContext , configFile : string ) {
@@ -50,7 +53,7 @@ export function purgeGeneratedFiles(context: BuildContext, fileNameSuffix: strin
5053export function doOptimizations ( context : BuildContext , dependencyMap : Map < string , Set < string > > ) {
5154 // remove decorators
5255 const modifiedMap = new Map ( dependencyMap ) ;
53- if ( getBooleanPropertyValue ( Constants . ENV_EXPERIMENTAL_PURGE_DECORATORS ) ) {
56+ if ( getBooleanPropertyValue ( Constants . ENV_PURGE_DECORATORS ) ) {
5457 removeDecorators ( context ) ;
5558 }
5659
@@ -70,15 +73,18 @@ export function doOptimizations(context: BuildContext, dependencyMap: Map<string
7073}
7174
7275function optimizationEnabled ( ) {
73- const purgeDecorators = getBooleanPropertyValue ( Constants . ENV_EXPERIMENTAL_PURGE_DECORATORS ) ;
76+ const purgeDecorators = getBooleanPropertyValue ( Constants . ENV_PURGE_DECORATORS ) ;
7477 const manualTreeshaking = getBooleanPropertyValue ( Constants . ENV_EXPERIMENTAL_MANUAL_TREESHAKING ) ;
7578 return purgeDecorators || manualTreeshaking ;
7679}
7780
7881function removeDecorators ( context : BuildContext ) {
7982 const jsFiles = context . fileCache . getAll ( ) . filter ( file => extname ( file . path ) === '.js' ) ;
8083 jsFiles . forEach ( jsFile => {
81- jsFile . content = purgeDecorators ( jsFile . path , jsFile . content ) ;
84+ let magicString = new MagicString ( jsFile . content ) ;
85+ magicString = purgeStaticFieldDecorators ( jsFile . path , jsFile . content , getStringPropertyValue ( Constants . ENV_VAR_IONIC_ANGULAR_DIR ) , getStringPropertyValue ( Constants . ENV_VAR_AT_ANGULAR_DIR ) , context . srcDir , magicString ) ;
86+ jsFile . content = magicString . toString ( ) ;
87+ // jsFile.content = removeTSickleClosureDeclarations(jsFile.path, jsFile.content, getStringPropertyValue(Constants.ENV_VAR_IONIC_ANGULAR_DIR), context.srcDir);
8288 } ) ;
8389}
8490
0 commit comments