This is an example of using WebPack to bundle node modules for Node.js Azure Functions. This can result in large cold start improvements.
🚧 This is an example and not officially supported. This does not yet work in Azure production - it requires a feature that's coming out in a release later this month! Will update this message when released. 🚧
-
Clone the repo:
git clone https://github.com/christopheranderson/azure-functions-webpack-sample.git
-
Install dependencies:
npm install
(this includes webpack as dev dependency) -
Build the project:
npm run build
(this run webpack) -
Running locally:
func run HttpTriggerJS
(assumes you've installed local tools -npm install -g azure-functions-cli
)
-
webpack.config.json
will build the./index.js
file at the root of the project, which includes references to all your JS functions. This will load all your dependencies.// ./index.js var HttpTriggerJS = require('./HttpTriggerJS/index') var HTTPJS2 = require('./HTTPJS2/index') module.exports = { HttpTriggerJS: HttpTriggerJS, HTTPJS2: HTTPJS2 }
-
When functions are run, the
function.json
contains a propertyscriptFile
which points at the./build/index.js
file and aentryPoint
property that points at the method for that given Function. This ensures the right function is loaded and that libraries can be shared (important for connection pools, etc.)."scriptFile":"../build/index.js", "entryPoint":"HTTPJS2",
-
Add the
webpack.config.json
into the root of your Function App -
Add
webpack
as a dev dependency and"build":"webpack"
to your scripts section in yourpackage.json
"scripts": { "build": "webpack", }, "devDependencies": { "webpack": "^2.2.1" }
-
Add an
index.js
file at the root of your Function App which references all your JS Functions as in the example -
Add the
entryPoint
andscriptFile
properties to each of your function'sfunction.json
files.