From af0b8786c3a878444a1a86aa97e03ad778c49e27 Mon Sep 17 00:00:00 2001 From: Jonas Aschenbrenner Date: Sun, 1 May 2016 16:30:14 -0700 Subject: [PATCH 1/3] Allow to include other modules before the lamda function gets loaded For example babel-polyfill --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index e5a6269..0250189 100644 --- a/index.js +++ b/index.js @@ -78,7 +78,11 @@ module.exports = function getPlugin(S) { // override entry and output webpackConfig.context = path.dirname(func.getFilePath()); - webpackConfig.entry = `./${handlerFileName}`; + if (Array.isArray(webpackConfig.entry)) { + webpackConfig.entry.push(`./${handlerFileName}`); + } else { + webpackConfig.entry = `./${handlerFileName}`; + } webpackConfig.output = { libraryTarget: 'commonjs', path: optimizedPath, From b30ded7ca9e0fe6578c5456dcaa5f2500d344379 Mon Sep 17 00:00:00 2001 From: Jonas Aschenbrenner Date: Sun, 1 May 2016 21:04:54 -0700 Subject: [PATCH 2/3] Adds documentation for loading modules before the lambda function --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 51eb814..1ab5943 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,13 @@ for an easy way to externalize all node modules. ### Source Maps Yes using `devtool: 'source-map'` works, include `require('source-map-support').install();` you'll have pretty stacktraces. + +### Loading additional modules before the lambda function module +If you need to load modules before your lambda function module is loaded, +you can specify those modules with entry option in your webpack config. +For example if you need to load the babel-polyfill, you can do that +by adding `entry: ['babel-polyfill']` to your webpack config. +This will first load the babel-polyfill module and then your lambda function module. ### Improving deploy performance From d25c568f38043e372338ff57c310e31f4ff4dfe5 Mon Sep 17 00:00:00 2001 From: Jonas Aschenbrenner Date: Sun, 1 May 2016 21:11:18 -0700 Subject: [PATCH 3/3] Extracts handler entry path into constant (DRY) --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 0250189..aef6db0 100644 --- a/index.js +++ b/index.js @@ -75,13 +75,14 @@ module.exports = function getPlugin(S) { const webpackConfig = Object.assign({}, config.webpackConfig); const handlerName = func.getHandler().split('.')[0]; const handlerFileName = `${handlerName}.${config.handlerExt}`; + const handlerEntryPath = `./${handlerFileName}`; // override entry and output webpackConfig.context = path.dirname(func.getFilePath()); if (Array.isArray(webpackConfig.entry)) { - webpackConfig.entry.push(`./${handlerFileName}`); + webpackConfig.entry.push(handlerEntryPath); } else { - webpackConfig.entry = `./${handlerFileName}`; + webpackConfig.entry = handlerEntryPath; } webpackConfig.output = { libraryTarget: 'commonjs',