@@ -2,23 +2,26 @@ import * as path from 'path';
22import * as CopyWebpackPlugin from 'copy-webpack-plugin' ;
33import * as HtmlWebpackPlugin from 'html-webpack-plugin' ;
44import * as webpack from 'webpack' ;
5- import { ForkCheckerPlugin } from 'awesome-typescript-loader' ;
6- import { CliConfig } from './config' ;
5+ import * as atl from 'awesome-typescript-loader' ;
6+
7+ import { findLazyModules } from './find-lazy-modules' ;
78
8- export function getWebpackCommonConfig ( projectRoot : string , sourceDir : string , outputDir : string ) {
99
10- let outputPath : string = path . resolve ( projectRoot , outputDir ) ;
10+ export function getWebpackCommonConfig ( projectRoot : string , sourceDir : string , outputDir : string ) {
11+ const sourceRoot = path . resolve ( projectRoot , sourceDir ) ;
12+ const outputPath = path . resolve ( projectRoot , outputDir ) ;
13+ const lazyModules = findLazyModules ( path . resolve ( projectRoot , sourceDir ) ) ;
1114
1215 return {
1316 devtool : 'source-map' ,
1417 resolve : {
1518 extensions : [ '' , '.ts' , '.js' ] ,
16- root : path . resolve ( projectRoot , `./ ${ sourceDir } ` )
19+ root : sourceRoot
1720 } ,
1821 context : path . resolve ( __dirname , './' ) ,
1922 entry : {
20- main : [ path . resolve ( projectRoot , `./ ${ sourceDir } / main.ts` ) ] ,
21- polyfills : path . resolve ( projectRoot , `./ ${ sourceDir } / polyfills.ts` )
23+ main : [ path . join ( sourceRoot , ' main.ts' ) ] ,
24+ polyfills : path . join ( sourceRoot , ' polyfills.ts' )
2225 } ,
2326 output : {
2427 path : outputPath ,
@@ -42,10 +45,9 @@ export function getWebpackCommonConfig(projectRoot: string, sourceDir: string, o
4245 loader : 'awesome-typescript-loader' ,
4346 query : {
4447 useForkChecker : true ,
45- tsconfig : path . resolve ( projectRoot , `./ ${ sourceDir } / tsconfig.json` )
48+ tsconfig : path . resolve ( sourceRoot , ' tsconfig.json' )
4649 }
47- } ,
48- {
50+ } , {
4951 loader : 'angular2-template-loader'
5052 }
5153 ] ,
@@ -61,9 +63,10 @@ export function getWebpackCommonConfig(projectRoot: string, sourceDir: string, o
6163 ]
6264 } ,
6365 plugins : [
64- new ForkCheckerPlugin ( ) ,
66+ new webpack . ContextReplacementPlugin ( / .* / , sourceRoot , lazyModules ) ,
67+ new atl . ForkCheckerPlugin ( ) ,
6568 new HtmlWebpackPlugin ( {
66- template : path . resolve ( projectRoot , `./ ${ sourceDir } / index.html` ) ,
69+ template : path . resolve ( sourceRoot , ' index.html' ) ,
6770 chunksSortMode : 'dependency'
6871 } ) ,
6972 new webpack . optimize . CommonsChunkPlugin ( {
@@ -79,7 +82,7 @@ export function getWebpackCommonConfig(projectRoot: string, sourceDir: string, o
7982 context : path . resolve ( projectRoot , './public' ) ,
8083 from : '**/*' ,
8184 to : outputPath
82- } ] )
85+ } ] ) ,
8386 ] ,
8487 node : {
8588 fs : 'empty' ,
@@ -90,4 +93,4 @@ export function getWebpackCommonConfig(projectRoot: string, sourceDir: string, o
9093 setImmediate : false
9194 }
9295 }
93- } ;
96+ }
0 commit comments