@@ -2,21 +2,27 @@ import * as path from 'path';
2
2
import * as CopyWebpackPlugin from 'copy-webpack-plugin' ;
3
3
import * as HtmlWebpackPlugin from 'html-webpack-plugin' ;
4
4
import * 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 { SystemJSRegisterPublicModules } from './webpack-plugin-systemjs-registry' ;
8
+ import { findLazyModules } from './find-lazy-modules' ;
9
+
7
10
8
11
export function getWebpackCommonConfig ( projectRoot : string , sourceDir : string ) {
12
+ const lazyModules = findLazyModules ( path . resolve ( projectRoot , sourceDir ) ) ;
13
+ const entries = Object . assign ( {
14
+ main : [ path . resolve ( projectRoot , `./${ sourceDir } /main.ts` ) ] ,
15
+ polyfills : path . resolve ( projectRoot , `./${ sourceDir } /polyfills.ts` )
16
+ } , lazyModules ) ;
17
+
9
18
return {
10
19
devtool : 'inline-source-map' ,
11
20
resolve : {
12
21
extensions : [ '' , '.ts' , '.js' ] ,
13
22
root : path . resolve ( projectRoot , `./${ sourceDir } ` )
14
23
} ,
15
24
context : path . resolve ( __dirname , './' ) ,
16
- entry : {
17
- main : [ path . resolve ( projectRoot , `./${ sourceDir } /main.ts` ) ] ,
18
- polyfills : path . resolve ( projectRoot , `./${ sourceDir } /polyfills.ts` )
19
- } ,
25
+ entry : entries ,
20
26
output : {
21
27
path : path . resolve ( projectRoot , './dist' ) ,
22
28
filename : '[name].bundle.js'
@@ -30,7 +36,16 @@ export function getWebpackCommonConfig(projectRoot: string, sourceDir: string) {
30
36
path . resolve ( projectRoot , 'node_modules/rxjs' ) ,
31
37
path . resolve ( projectRoot , 'node_modules/@angular' ) ,
32
38
]
33
- }
39
+ } ,
40
+ {
41
+ test : / ( s y s t e m j s _ c o m p o n e n t _ r e s o l v e r | s y s t e m _ j s _ n g _ m o d u l e _ f a c t o r y _ l o a d e r ) \. j s $ / ,
42
+ loader : 'string-replace-loader' ,
43
+ query : {
44
+ search : '(lang_1(.*[\\n\\r]\\s*\\.|\\.))?(global(.*[\\n\\r]\\s*\\.|\\.))?(System|SystemJS)(.*[\\n\\r]\\s*\\.|\\.)import' ,
45
+ replace : 'System.import' ,
46
+ flags : 'g'
47
+ }
48
+ } ,
34
49
] ,
35
50
loaders : [
36
51
{
@@ -42,8 +57,7 @@ export function getWebpackCommonConfig(projectRoot: string, sourceDir: string) {
42
57
useForkChecker : true ,
43
58
tsconfig : path . resolve ( projectRoot , `./${ sourceDir } /tsconfig.json` )
44
59
}
45
- } ,
46
- {
60
+ } , {
47
61
loader : 'angular2-template-loader'
48
62
}
49
63
] ,
@@ -59,13 +73,13 @@ export function getWebpackCommonConfig(projectRoot: string, sourceDir: string) {
59
73
]
60
74
} ,
61
75
plugins : [
62
- new ForkCheckerPlugin ( ) ,
76
+ new atl . ForkCheckerPlugin ( ) ,
63
77
new HtmlWebpackPlugin ( {
64
78
template : path . resolve ( projectRoot , `./${ sourceDir } /index.html` ) ,
65
79
chunksSortMode : 'dependency'
66
80
} ) ,
67
81
new webpack . optimize . CommonsChunkPlugin ( {
68
- name : [ 'polyfills' ]
82
+ name : 'polyfills'
69
83
} ) ,
70
84
new webpack . optimize . CommonsChunkPlugin ( {
71
85
minChunks : Infinity ,
@@ -77,7 +91,35 @@ export function getWebpackCommonConfig(projectRoot: string, sourceDir: string) {
77
91
context : path . resolve ( projectRoot , './public' ) ,
78
92
from : '**/*' ,
79
93
to : path . resolve ( projectRoot , './dist' )
80
- } ] )
94
+ } ] ) ,
95
+ // new SystemJSRegisterPublicModules({
96
+ // // automatically configure SystemJS to load webpack chunks (defaults to true)
97
+ // bundlesConfigForChunks: true,
98
+ //
99
+ // // select which modules to expose as public modules
100
+ // registerModules: [
101
+ // // "default" filters provided are "local" and "public"
102
+ // { filter: 'public' },
103
+ // //
104
+ // // // keyname allows a custom naming system for public modules
105
+ // // {
106
+ // // filter: 'local',
107
+ // // keyname: 'app/[relPath]'
108
+ // // },
109
+ // //
110
+ // // // keyname can be a function
111
+ // // {
112
+ // // filter: 'public',
113
+ // // keyname: (module) => 'publicModule-' + module.id
114
+ // // },
115
+ // //
116
+ // // // filter can also be a function
117
+ // // {
118
+ // // filter: (m) => m.relPath.match(/src/),
119
+ // // keyname: 'random-naming-system-[id]'
120
+ // // }
121
+ // ]
122
+ // })
81
123
] ,
82
124
node : {
83
125
fs : 'empty' ,
@@ -88,4 +130,4 @@ export function getWebpackCommonConfig(projectRoot: string, sourceDir: string) {
88
130
setImmediate : false
89
131
}
90
132
}
91
- } ;
133
+ }
0 commit comments