File tree Expand file tree Collapse file tree 6 files changed +34
-9
lines changed Expand file tree Collapse file tree 6 files changed +34
-9
lines changed Original file line number Diff line number Diff line change 4242 "default" : " dist/" ,
4343 "description" : " The output directory for build results."
4444 },
45+ "platform" : {
46+ "type" : " string" ,
47+ "description" : " The destination platform of app."
48+ },
4549 "assets" : {
4650 "type" : " array" ,
4751 "description" : " List of application assets." ,
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { CliConfig } from './config';
33import { BuildOptions } from './build-options' ;
44import {
55 getBrowserConfig ,
6+ getServerConfig ,
67 getCommonConfig ,
78 getDevConfig ,
89 getProdConfig ,
@@ -37,13 +38,23 @@ export class NgCliWebpackConfig {
3738 }
3839
3940 public buildConfig ( ) {
40- let webpackConfigs = [
41- getCommonConfig ( this . wco ) ,
42- getBrowserConfig ( this . wco ) ,
43- getStylesConfig ( this . wco ) ,
44- this . getTargetConfig ( this . wco )
41+ let webpackConfigs : any [ ] = [
42+ getCommonConfig ( this . wco )
4543 ] ;
4644
45+ switch ( this . wco . appConfig . platform ) {
46+ case 'browser' :
47+ webpackConfigs . push ( getBrowserConfig ( this . wco ) , getStylesConfig ( this . wco ) ) ;
48+ break ;
49+ case 'server' :
50+ webpackConfigs . push ( getServerConfig ( ) ) ;
51+ break ;
52+ default :
53+ throw new Error ( 'Only browser and server platforms are supported' ) ;
54+ }
55+
56+ webpackConfigs . push ( this . getTargetConfig ( this . wco ) ) ;
57+
4758 if ( this . wco . appConfig . main || this . wco . appConfig . polyfills ) {
4859 const typescriptConfigPartial = this . wco . buildOptions . aot
4960 ? getAotConfig ( this . wco )
@@ -106,6 +117,7 @@ export class NgCliWebpackConfig {
106117 public addAppConfigDefaults ( appConfig : any ) {
107118 const appConfigDefaults : any = {
108119 testTsconfig : appConfig . tsconfig ,
120+ platform : 'browser' ,
109121 scripts : [ ] ,
110122 styles : [ ]
111123 } ;
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ export function getBrowserConfig(wco: WebpackConfigOptions) {
1313
1414 const appRoot = path . resolve ( projectRoot , appConfig . root ) ;
1515 const nodeModules = path . resolve ( projectRoot , 'node_modules' ) ;
16+ const entryPoints : { [ key : string ] : string [ ] } = { } ;
1617
1718 let extraPlugins : any [ ] = [ ] ;
1819
@@ -22,6 +23,10 @@ export function getBrowserConfig(wco: WebpackConfigOptions) {
2223 ...extraEntryParser ( appConfig . styles , appRoot , 'styles' )
2324 ] ) ;
2425
26+ if ( appConfig . polyfills ) {
27+ entryPoints [ 'polyfills' ] = [ path . resolve ( appRoot , appConfig . polyfills ) ] ;
28+ }
29+
2530 if ( buildOptions . vendorChunk ) {
2631 extraPlugins . push ( new webpack . optimize . CommonsChunkPlugin ( {
2732 name : 'vendor' ,
@@ -31,6 +36,7 @@ export function getBrowserConfig(wco: WebpackConfigOptions) {
3136 }
3237
3338 return {
39+ entry : entryPoints ,
3440 plugins : [
3541 new HtmlWebpackPlugin ( {
3642 template : path . resolve ( appRoot , appConfig . index ) ,
Original file line number Diff line number Diff line change @@ -33,10 +33,6 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
3333 entryPoints [ 'main' ] = [ path . resolve ( appRoot , appConfig . main ) ] ;
3434 }
3535
36- if ( appConfig . polyfills ) {
37- entryPoints [ 'polyfills' ] = [ path . resolve ( appRoot , appConfig . polyfills ) ] ;
38- }
39-
4036 // determine hashing format
4137 const hashFormat = getOutputHashFormat ( buildOptions . outputHashing ) ;
4238
Original file line number Diff line number Diff line change 11export * from './browser' ;
2+ export * from './server' ;
23export * from './common' ;
34export * from './development' ;
45export * from './production' ;
Original file line number Diff line number Diff line change 1+ export function getServerConfig ( ) {
2+
3+ return {
4+ target : 'node'
5+ } ;
6+ }
You can’t perform that action at this time.
0 commit comments