Using Webpack with Foxx
Because the ArangoDB JavaScript environment is largely compatible with Node.js, the starting point looks fairly similar:
Foxx extends the object with a special context
property that reflects the current service context. As Webpack compiles multiple modules into a single file your code will not be able to access the real module
object provided by ArangoDB.
const { context } = require("@arangodb/locals");
This object is identical to module.context
and can be used as a drop-in replacement:
By default Webpack will attempt to include any dependency your code imports. This makes it easy to use third-party modules without worrying about but causes problems when importing modules provided by ArangoDB.
// ...
externals: [/^@arangodb(\/|$)/]
};
You can also use this to exclude other modules provided by ArangoDB, like the joi
validation library:
As far as Webpack is concerned, scripts are additional entry points:
const path = require("path");
context: path.resolve(__dirname, "src"),
entry: {
main: "./index.js",
setup: "./scripts/setup.js"
}