Created
July 10, 2018 23:30
-
-
Save Gomah/2789044ce28e86eeaf08a9e2be177a5f to your computer and use it in GitHub Desktop.
Build & serve Netlify lambda functions with Vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import buildLambda from 'netlify-lambda/lib/build'; | |
export default async function({ service: { commands, projectOptions } }) { | |
const { build, serve } = commands; | |
const buildFn = build.fn; | |
const serveFn = serve.fn; | |
build.fn = async (...args) => { | |
try { | |
const res = await buildFn(...args); | |
const stats = await buildLambda.run('src/lambda'); | |
console.log(stats.toString({ color: true })); | |
return res; | |
} catch (error) { | |
console.error(error); | |
throw new Error(error); | |
} | |
}; | |
serve.fn = (...args) => { | |
const devServer = projectOptions.devServer || {}; | |
if (!devServer.proxy) { | |
devServer.proxy = {}; | |
} | |
devServer.proxy['/.netlify/functions'] = { | |
target: 'http://localhost:9000', | |
pathRewrite: { | |
'^/\\.netlify/functions': '', | |
}, | |
}; | |
return serveFn(...args); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment