From 7a828ea25a0c0ac0bcba6eb90f211e0d44eda747 Mon Sep 17 00:00:00 2001 From: danilo neves cruz Date: Wed, 19 Sep 2018 22:43:29 -0300 Subject: [PATCH 1/4] add webpack additional config option --- index.js | 5 +++-- package.json | 1 + serve.js | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 02b4390..09904bd 100644 --- a/index.js +++ b/index.js @@ -6,11 +6,12 @@ module.exports = (api, projectOptions) => { const {build, serve} = api.service.commands; const buildFn = build.fn; const serveFn = serve.fn; + const webpackConfig = projectOptions.pluginOptions && projectOptions.pluginOptions.netlify && projectOptions.pluginOptions.netlify.webpackConfig; build.fn = (...args) => { return buildFn(...args).then((res) => { return lambdaBuild - .run("src/lambda") + .run("src/lambda", webpackConfig) .then(function(stats) { console.log(stats.toString({ color: true })) return res @@ -34,7 +35,7 @@ module.exports = (api, projectOptions) => { } } - const forked = fork(path.join(__dirname, 'serve.js')) + const forked = fork(path.join(__dirname, 'serve.js'), webpackConfig ? [webpackConfig] : null) return serveFn(...args) } } \ No newline at end of file diff --git a/package.json b/package.json index 0fececa..b51a8e5 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ }, "author": "Netlify", "license": "MIT", + "repository": "netlify/vue-cli-plugin-netlify-lambda", "dependencies": { "netlify-lambda": "1.0.0-babel-7-beta" } diff --git a/serve.js b/serve.js index 40908c3..542a862 100644 --- a/serve.js +++ b/serve.js @@ -2,7 +2,8 @@ const serve = require("netlify-lambda/lib/serve"); const build = require("netlify-lambda/lib/build"); const server = serve.listen(9000) -build.watch("src/lambda", null, function(err, stats) { +const [, , webpackConfig] = process.argv; +build.watch("src/lambda", webpackConfig, function(err, stats) { if (err) { console.error(err); return; From 1397583c8978899eb2369fc6c2f8c0050700f0cc Mon Sep 17 00:00:00 2001 From: danilo neves cruz Date: Thu, 20 Sep 2018 01:57:18 -0300 Subject: [PATCH 2/4] add config ui --- ui.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 ui.js diff --git a/ui.js b/ui.js new file mode 100644 index 0000000..fba480c --- /dev/null +++ b/ui.js @@ -0,0 +1,40 @@ +const fs = require('fs'); +const path = require('path'); + +function getConfigData(data) { + return (data.vue && data.vue.pluginOptions && data.vue.pluginOptions.netlify) || {}; +} + +module.exports = api => api.describeConfig({ + id: 'com.netlify.netlify-lambda', + name: 'Netlify configuration', + description: 'Configure Netlify Functions', + link: 'https://github.com/netlify/vue-cli-plugin-netlify-lambda', + files: { + vue: { + js: ['vue.config.js'], + }, + }, + onRead({ data, cwd }) { + return { + prompts: [ + { + name: 'webpackConfig', + type: 'input', + default: null, + value: getConfigData(data).webpackConfig, + validate: input => fs.existsSync(path.join(cwd, input)), + message: 'Webpack config module', + description: 'Additional webpack configuration', + }, + ], + }; + }, + async onWrite({ api: writeApi, prompts }) { + const result = {}; + for (const prompt of prompts) { + result[`pluginOptions.netlify.${prompt.id}`] = await writeApi.getAnswer(prompt.id); + } + writeApi.setData('vue', result); + }, +}); From 2ac4fa17fa3a0a9ec2c462401de615acbce9ea0b Mon Sep 17 00:00:00 2001 From: danilo neves cruz Date: Thu, 20 Sep 2018 17:13:25 -0300 Subject: [PATCH 3/4] parallel build --- index.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 09904bd..0d65080 100644 --- a/index.js +++ b/index.js @@ -8,19 +8,18 @@ module.exports = (api, projectOptions) => { const serveFn = serve.fn; const webpackConfig = projectOptions.pluginOptions && projectOptions.pluginOptions.netlify && projectOptions.pluginOptions.netlify.webpackConfig; - build.fn = (...args) => { - return buildFn(...args).then((res) => { - return lambdaBuild - .run("src/lambda", webpackConfig) - .then(function(stats) { - console.log(stats.toString({ color: true })) - return res - }) - .catch(function(err) { - console.error(err) - process.exit(1) - }) - }) + build.fn = async (...args) => { + try { + const [res, stats] = await Promise.all([ + buildFn(...args), + lambdaBuild.run('src/lambda', webpackConfig), + ]); + console.log(stats.toString({ color: true })); + return res; + } catch (err) { + console.error(err); + process.exit(1); + } } serve.fn = (...args) => { From b4539d87f67a43c7f4c859b04b0f74f47da0a486 Mon Sep 17 00:00:00 2001 From: danilo neves cruz Date: Fri, 21 Sep 2018 10:49:13 -0300 Subject: [PATCH 4/4] use original netlify-lambda serve --- index.js | 2 +- serve.js | 17 ----------------- 2 files changed, 1 insertion(+), 18 deletions(-) delete mode 100644 serve.js diff --git a/index.js b/index.js index 0d65080..91ea0e5 100644 --- a/index.js +++ b/index.js @@ -34,7 +34,7 @@ module.exports = (api, projectOptions) => { } } - const forked = fork(path.join(__dirname, 'serve.js'), webpackConfig ? [webpackConfig] : null) + fork(require.resolve('netlify-lambda'), ['serve', 'src/lambda', ...(webpackConfig ? ['-c', webpackConfig] : [])]); return serveFn(...args) } } \ No newline at end of file diff --git a/serve.js b/serve.js deleted file mode 100644 index 542a862..0000000 --- a/serve.js +++ /dev/null @@ -1,17 +0,0 @@ -const serve = require("netlify-lambda/lib/serve"); -const build = require("netlify-lambda/lib/build"); - -const server = serve.listen(9000) -const [, , webpackConfig] = process.argv; -build.watch("src/lambda", webpackConfig, function(err, stats) { - if (err) { - console.error(err); - return; - } - - stats.compilation.chunks.forEach(function(chunk) { - server.clearCache(chunk.name); - }); - - console.log(stats.toString({ color: true })); -}); \ No newline at end of file