Skip to content
This repository was archived by the owner on Sep 8, 2021. It is now read-only.

Commit 6abd244

Browse files
divyatest
authored andcommitted
refactor: Update service plugin to use custom runner
1 parent dd35efd commit 6abd244

File tree

1 file changed

+33
-34
lines changed

1 file changed

+33
-34
lines changed

index.js

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,39 @@
11
const { fork } = require('child_process')
22
const path = require('path')
33
const 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

Comments
 (0)