1- import { extname } from 'path' ;
1+ import { extname , join } from 'path' ;
22import { Logger } from './logger/logger' ;
33import { fillConfigDefaults , getUserConfigFile , replacePathVars } from './util/config' ;
44import * as Constants from './util/constants' ;
55import { BuildError } from './util/errors' ;
6- import { getBooleanPropertyValue , webpackStatsToDependencyMap , printDependencyMap } from './util/helpers' ;
6+ import { getBooleanPropertyValue , webpackStatsToDependencyMap , printDependencyMap , unlinkAsync } from './util/helpers' ;
77import { BuildContext , TaskInfo } from './util/interfaces' ;
88import { runWebpackFullBuild , WebpackConfig } from './webpack' ;
99import { purgeDecorators } from './optimization/decorators' ;
@@ -23,17 +23,24 @@ export function optimization(context: BuildContext, configFile: string) {
2323
2424function optimizationWorker ( context : BuildContext , configFile : string ) {
2525 const webpackConfig = getConfig ( context , configFile ) ;
26+ let dependencyMap : Map < string , Set < string > > = null ;
2627 return runWebpackFullBuild ( webpackConfig ) . then ( ( stats : any ) => {
27- const dependencyMap = webpackStatsToDependencyMap ( context , stats ) ;
28+ dependencyMap = webpackStatsToDependencyMap ( context , stats ) ;
2829 if ( getBooleanPropertyValue ( Constants . ENV_PRINT_ORIGINAL_DEPENDENCY_TREE ) ) {
2930 Logger . debug ( 'Original Dependency Map Start' ) ;
3031 printDependencyMap ( dependencyMap ) ;
3132 Logger . debug ( 'Original Dependency Map End' ) ;
3233 }
34+ return deleteOptimizationJsFile ( join ( webpackConfig . output . path , webpackConfig . output . filename ) ) ;
35+ } ) . then ( ( ) => {
3336 return doOptimizations ( context , dependencyMap ) ;
3437 } ) ;
3538}
3639
40+ export function deleteOptimizationJsFile ( fileToDelete : string ) {
41+ return unlinkAsync ( fileToDelete ) ;
42+ }
43+
3744export function doOptimizations ( context : BuildContext , dependencyMap : Map < string , Set < string > > ) {
3845 // remove decorators
3946 const modifiedMap = new Map ( dependencyMap ) ;
0 commit comments