@@ -46,12 +46,8 @@ export function getWebpackCommonConfig(
4646 main : [ appMain ]
4747 } ;
4848
49- if ( ! ( environment in appConfig . environments ) ) {
50- throw new SilentError ( `Environment "${ environment } " does not exist.` ) ;
51- }
52-
5349 // process global scripts
54- if ( appConfig . scripts . length > 0 ) {
50+ if ( appConfig . scripts && appConfig . scripts . length > 0 ) {
5551 const globalScripts = extraEntryParser ( appConfig . scripts , appRoot , 'scripts' ) ;
5652
5753 // add entry points and lazy chunks
@@ -67,7 +63,7 @@ export function getWebpackCommonConfig(
6763 }
6864
6965 // process global styles
70- if ( appConfig . styles . length === 0 ) {
66+ if ( ! appConfig . styles || appConfig . styles . length === 0 ) {
7167 // create css loaders for component css
7268 extraRules . push ( ...makeCssLoaders ( ) ) ;
7369 } else {
@@ -104,6 +100,33 @@ export function getWebpackCommonConfig(
104100 } ) ) ;
105101 }
106102
103+ // process environment file replacement
104+ if ( appConfig . environments ) {
105+ if ( ! ( 'source' in appConfig . environments ) ) {
106+ throw new SilentError ( `Environment configuration does not contain "source" entry.` ) ;
107+ }
108+ if ( ! ( environment in appConfig . environments ) ) {
109+ throw new SilentError ( `Environment "${ environment } " does not exist.` ) ;
110+ }
111+
112+ extraPlugins . push ( new webpack . NormalModuleReplacementPlugin (
113+ // This plugin is responsible for swapping the environment files.
114+ // Since it takes a RegExp as first parameter, we need to escape the path.
115+ // See https://webpack.github.io/docs/list-of-plugins.html#normalmodulereplacementplugin
116+ new RegExp ( path . resolve ( appRoot , appConfig . environments [ 'source' ] )
117+ . replace ( / [ \- \[ \] \/ \{ \} \( \) \* \+ \? \. \\ \^ \$ \| ] / g, '\\$&' ) ) ,
118+ path . resolve ( appRoot , appConfig . environments [ environment ] )
119+ ) ) ;
120+ }
121+
122+ // process asset entries
123+ if ( appConfig . assets ) {
124+ extraPlugins . push ( new GlobCopyWebpackPlugin ( {
125+ patterns : appConfig . assets ,
126+ globOptions : { cwd : appRoot , dot : true , ignore : '**/.gitkeep' }
127+ } ) ) ;
128+ }
129+
107130 if ( progress ) { extraPlugins . push ( new ProgressPlugin ( { profile : verbose , colors : true } ) ) ; }
108131
109132 return {
@@ -145,22 +168,10 @@ export function getWebpackCommonConfig(
145168 new BaseHrefWebpackPlugin ( {
146169 baseHref : baseHref
147170 } ) ,
148- new webpack . NormalModuleReplacementPlugin (
149- // This plugin is responsible for swapping the environment files.
150- // Since it takes a RegExp as first parameter, we need to escape the path.
151- // See https://webpack.github.io/docs/list-of-plugins.html#normalmodulereplacementplugin
152- new RegExp ( path . resolve ( appRoot , appConfig . environments [ 'source' ] )
153- . replace ( / [ \- \[ \] \/ \{ \} \( \) \* \+ \? \. \\ \^ \$ \| ] / g, '\\$&' ) ) ,
154- path . resolve ( appRoot , appConfig . environments [ environment ] )
155- ) ,
156171 new webpack . optimize . CommonsChunkPlugin ( {
157172 minChunks : Infinity ,
158173 name : 'inline'
159174 } ) ,
160- new GlobCopyWebpackPlugin ( {
161- patterns : appConfig . assets ,
162- globOptions : { cwd : appRoot , dot : true , ignore : '**/.gitkeep' }
163- } ) ,
164175 new webpack . LoaderOptionsPlugin ( {
165176 test : / \. ( c s s | s c s s | s a s s | l e s s | s t y l ) $ / ,
166177 options : {
0 commit comments