@@ -46,12 +46,8 @@ export function getWebpackCommonConfig(
46
46
main : [ appMain ]
47
47
} ;
48
48
49
- if ( ! ( environment in appConfig . environments ) ) {
50
- throw new SilentError ( `Environment "${ environment } " does not exist.` ) ;
51
- }
52
-
53
49
// process global scripts
54
- if ( appConfig . scripts . length > 0 ) {
50
+ if ( appConfig . scripts && appConfig . scripts . length > 0 ) {
55
51
const globalScripts = extraEntryParser ( appConfig . scripts , appRoot , 'scripts' ) ;
56
52
57
53
// add entry points and lazy chunks
@@ -67,7 +63,7 @@ export function getWebpackCommonConfig(
67
63
}
68
64
69
65
// process global styles
70
- if ( appConfig . styles . length === 0 ) {
66
+ if ( ! appConfig . styles || appConfig . styles . length === 0 ) {
71
67
// create css loaders for component css
72
68
extraRules . push ( ...makeCssLoaders ( ) ) ;
73
69
} else {
@@ -104,6 +100,33 @@ export function getWebpackCommonConfig(
104
100
} ) ) ;
105
101
}
106
102
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
+
107
130
if ( progress ) { extraPlugins . push ( new ProgressPlugin ( { profile : verbose , colors : true } ) ) ; }
108
131
109
132
return {
@@ -145,22 +168,10 @@ export function getWebpackCommonConfig(
145
168
new BaseHrefWebpackPlugin ( {
146
169
baseHref : baseHref
147
170
} ) ,
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
- ) ,
156
171
new webpack . optimize . CommonsChunkPlugin ( {
157
172
minChunks : Infinity ,
158
173
name : 'inline'
159
174
} ) ,
160
- new GlobCopyWebpackPlugin ( {
161
- patterns : appConfig . assets ,
162
- globOptions : { cwd : appRoot , dot : true , ignore : '**/.gitkeep' }
163
- } ) ,
164
175
new webpack . LoaderOptionsPlugin ( {
165
176
test : / \. ( c s s | s c s s | s a s s | l e s s | s t y l ) $ / ,
166
177
options : {
0 commit comments