1
- import { extname , join } from 'path' ;
1
+ import { extname } from 'path' ;
2
+
3
+ import * as MagicString from 'magic-string' ;
4
+
2
5
import { Logger } from './logger/logger' ;
3
6
import { fillConfigDefaults , getUserConfigFile , replacePathVars } from './util/config' ;
4
7
import * as Constants from './util/constants' ;
5
8
import { BuildError } from './util/errors' ;
6
- import { getBooleanPropertyValue , webpackStatsToDependencyMap , printDependencyMap } from './util/helpers' ;
9
+ import { getBooleanPropertyValue , getStringPropertyValue , webpackStatsToDependencyMap , printDependencyMap } from './util/helpers' ;
7
10
import { BuildContext , TaskInfo } from './util/interfaces' ;
8
11
import { runWebpackFullBuild , WebpackConfig } from './webpack' ;
9
- import { purgeDecorators } from './optimization/decorators' ;
12
+ import { purgeStaticFieldDecorators } from './optimization/decorators' ;
10
13
import { getAppModuleNgFactoryPath , calculateUnusedComponents , purgeUnusedImportsAndExportsFromIndex , purgeComponentNgFactoryImportAndUsage , purgeProviderControllerImportAndUsage , purgeProviderClassNameFromIonicModuleForRoot } from './optimization/treeshake' ;
11
14
12
15
export function optimization ( context : BuildContext , configFile : string ) {
@@ -50,7 +53,7 @@ export function purgeGeneratedFiles(context: BuildContext, fileNameSuffix: strin
50
53
export function doOptimizations ( context : BuildContext , dependencyMap : Map < string , Set < string > > ) {
51
54
// remove decorators
52
55
const modifiedMap = new Map ( dependencyMap ) ;
53
- if ( getBooleanPropertyValue ( Constants . ENV_EXPERIMENTAL_PURGE_DECORATORS ) ) {
56
+ if ( getBooleanPropertyValue ( Constants . ENV_PURGE_DECORATORS ) ) {
54
57
removeDecorators ( context ) ;
55
58
}
56
59
@@ -70,15 +73,18 @@ export function doOptimizations(context: BuildContext, dependencyMap: Map<string
70
73
}
71
74
72
75
function optimizationEnabled ( ) {
73
- const purgeDecorators = getBooleanPropertyValue ( Constants . ENV_EXPERIMENTAL_PURGE_DECORATORS ) ;
76
+ const purgeDecorators = getBooleanPropertyValue ( Constants . ENV_PURGE_DECORATORS ) ;
74
77
const manualTreeshaking = getBooleanPropertyValue ( Constants . ENV_EXPERIMENTAL_MANUAL_TREESHAKING ) ;
75
78
return purgeDecorators || manualTreeshaking ;
76
79
}
77
80
78
81
function removeDecorators ( context : BuildContext ) {
79
82
const jsFiles = context . fileCache . getAll ( ) . filter ( file => extname ( file . path ) === '.js' ) ;
80
83
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);
82
88
} ) ;
83
89
}
84
90
0 commit comments