Skip to content

Instantly share code, notes, and snippets.

@Gomah
Created July 10, 2018 23:30
Show Gist options
  • Save Gomah/2789044ce28e86eeaf08a9e2be177a5f to your computer and use it in GitHub Desktop.
Save Gomah/2789044ce28e86eeaf08a9e2be177a5f to your computer and use it in GitHub Desktop.
Build & serve Netlify lambda functions with Vue
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