File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ const wpwatch = require('./lib/wpwatch');
99const cleanup = require ( './lib/cleanup' ) ;
1010const run = require ( './lib/run' ) ;
1111const prepareLocalInvoke = require ( './lib/prepareLocalInvoke' ) ;
12+ const prepareOfflineInvoke = require ( './lib/prepareOfflineInvoke' ) ;
1213const packExternalModules = require ( './lib/packExternalModules' ) ;
1314const packageModules = require ( './lib/packageModules' ) ;
1415const lib = require ( './lib' ) ;
@@ -39,7 +40,8 @@ class ServerlessWebpack {
3940 run ,
4041 packExternalModules ,
4142 packageModules ,
42- prepareLocalInvoke
43+ prepareLocalInvoke ,
44+ prepareOfflineInvoke
4345 ) ;
4446
4547 this . commands = {
@@ -125,12 +127,12 @@ class ServerlessWebpack {
125127 . then ( ( ) => BbPromise . reject ( new this . serverless . classes . Error ( 'serve has been removed. Use serverless-offline instead.' ) ) ) ,
126128
127129 'before:offline:start' : ( ) => BbPromise . bind ( this )
128- . then ( this . validate )
130+ . then ( this . prepareOfflineInvoke )
129131 . then ( this . compile )
130132 . then ( this . wpwatch ) ,
131133
132134 'before:offline:start:init' : ( ) => BbPromise . bind ( this )
133- . then ( this . validate )
135+ . then ( this . prepareOfflineInvoke )
134136 . then ( this . compile )
135137 . then ( this . wpwatch ) ,
136138
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const _ = require ( 'lodash' ) ;
4+ const path = require ( 'path' ) ;
5+
6+ /**
7+ * Special settings for use with serverless-offline.
8+ */
9+
10+ module . exports = {
11+ prepareOfflineInvoke ( ) {
12+
13+ // Use service packaging for compile
14+ _ . set ( this . serverless , 'service.package.individually' , false ) ;
15+
16+ return this . validate ( )
17+ . then ( ( ) => {
18+ // Set offline location automatically if not set manually
19+ if ( ! this . options . location && ! _ . get ( this . serverless , 'service.custom.serverless-offline.location' ) ) {
20+ _ . set ( this . serverless , 'service.custom.serverless-offline.location' ,
21+ path . relative ( this . serverless . config . servicePath , path . join ( this . webpackOutputPath , 'service' ) )
22+ ) ;
23+ }
24+ return null ;
25+ } ) ;
26+ }
27+ } ;
Original file line number Diff line number Diff line change @@ -15,7 +15,8 @@ const _ = require('lodash');
1515const preferredExtensions = [
1616 '.js' ,
1717 '.ts' ,
18- '.jsx'
18+ '.jsx' ,
19+ '.tsx'
1920] ;
2021
2122module . exports = {
Original file line number Diff line number Diff line change @@ -9,14 +9,14 @@ module.exports = {
99
1010 const compiler = webpack ( this . webpackConfig ) ;
1111 compiler . watch ( { } , ( err , stats ) => {
12- if ( err ) {
13- throw err ;
14- }
12+ if ( err ) {
13+ throw err ;
14+ }
1515
16- if ( stats ) {
17- console . log ( stats . toString ( ) ) ;
18- }
19- } ) ;
16+ if ( stats ) {
17+ console . log ( stats . toString ( ) ) ; // eslint-disable-line no-console
18+ }
19+ } ) ;
2020
2121 return BbPromise . resolve ( ) ;
2222 } ,
You can’t perform that action at this time.
0 commit comments