@@ -135,6 +135,10 @@ module.exports = function(S) {
135
135
. then ( ( webpackConfig ) => this . _webpackCompile ( R . merge ( webpackConfig , {
136
136
entry : path . join ( pathDist , webpackConfig . entry ) ,
137
137
} ) ) )
138
+ . then ( ( stats ) =>
139
+ this . createDistDir ( path . join ( pathDist , 'node_modules' ) )
140
+ . then ( ( modulesDist ) => this . _copyExternalModules ( stats , modulesDist ) )
141
+ )
138
142
. then ( ( ) => pathDist ) ;
139
143
} ) ;
140
144
}
@@ -192,6 +196,38 @@ module.exports = function(S) {
192
196
} ) ;
193
197
}
194
198
199
+ _copyExternalModules ( stats , pathDist ) {
200
+ const options = {
201
+ hash : false ,
202
+ version : false ,
203
+ timings : false ,
204
+ assets : false ,
205
+ chunks : false ,
206
+ modules : true ,
207
+ reasons : false ,
208
+ children : false ,
209
+ source : false ,
210
+ errors : false ,
211
+ errorDetails : false ,
212
+ warnings : false ,
213
+ publicPath : false ,
214
+ exclude : [ / ^ (? ! e x t e r n a l ) / ] ,
215
+ } ;
216
+
217
+ const natives = process . binding ( 'natives' ) ;
218
+ const projectPath = S . config . projectPath ;
219
+ const externalModules = stats . toJson ( options ) . modules ;
220
+ const moduleNames = externalModules
221
+ . map ( module => / e x t e r n a l " ( .+ ) " / . exec ( module . identifier ) [ 1 ] )
222
+ // exclude aws-sdk since it is provided by lambda
223
+ // also exclude native node.js modules
224
+ . filter ( id => id !== 'aws-sdk' && ! natives [ id ] ) ;
225
+ return Promise . all ( moduleNames . map ( moduleName => {
226
+ const modulePath = path . join ( projectPath , 'node_modules' , moduleName ) ;
227
+ SCli . log ( 'Copy module: ' + moduleName ) ;
228
+ return fs . copy ( modulePath , path . join ( pathDist , moduleName ) ) ;
229
+ } ) ) ;
230
+ }
195
231
196
232
/**
197
233
* Get Handler
0 commit comments