11const { fork } = require ( 'child_process' )
22const path = require ( 'path' )
33const lambdaBuild = require ( 'netlify-lambda/lib/build' )
4+ const lambdaServe = require ( "netlify-lambda/lib/serve" ) ;
45
5- module . exports = ( api , projectOptions ) => {
6- const { build, serve} = api . service . commands ;
7- const buildFn = build . fn ;
8- const serveFn = serve . fn ;
9-
10- build . fn = ( ...args ) => {
11- return buildFn ( ...args ) . then ( ( res ) => {
12- return lambdaBuild
13- . run ( "src/lambda" )
14- . then ( function ( stats ) {
15- console . log ( stats . toString ( { color : true } ) )
16- return res
17- } )
18- . catch ( function ( err ) {
19- console . error ( err )
20- process . exit ( 1 )
21- } )
6+ const buildFunction = ( ) => {
7+ return lambdaBuild
8+ . run ( "src/lambda" )
9+ . then ( stats => {
10+ console . log ( stats . toString ( { color : true } ) )
2211 } )
23- }
24-
25- serve . fn = ( ...args ) => {
26- const devServer = api . service . projectOptions . devServer = api . service . projectOptions . devServer || { }
27- if ( ! devServer . proxy ) {
28- devServer . proxy = { }
29- }
30- devServer . proxy [ '/.netlify/functions' ] = {
31- "target" : "http://localhost:9000" ,
32- "pathRewrite" : {
33- "^/\\.netlify/functions" : ""
34- }
35- }
12+ . catch ( err => {
13+ console . log ( err )
14+ process . exit ( 1 )
15+ } )
16+ }
17+ const serveFunction = ( ) => {
18+ return lambdaServe
19+ . listen ( '9000' )
20+ }
3621
37- const forked = fork ( path . join ( __dirname , 'serve.js' ) )
38- return serveFn ( ...args )
39- }
40- }
22+ module . exports = ( api , projectOptions ) => {
23+ api . registerCommand (
24+ `netlify-lambda:build` ,
25+ {
26+ description : "build a netlify function" ,
27+ usage : "vue-cli-service netlify-lambda"
28+ } ,
29+ buildFunction
30+ )
31+ api . registerCommand (
32+ `netlify-lambda:serve` ,
33+ {
34+ description : "build a netlify function" ,
35+ usage : "vue-cli-service netlify-lambda"
36+ } ,
37+ serveFunction
38+ )
39+ }
0 commit comments