2

I would like to split up Excel Custom Function declarations into multiple files for code cleanliness. I changed the webpack entry.functions into an array and added the two separate files:

module.exports = async (env, options) => {
  const dev = options.mode === "development";
  const buildType = dev ? "dev" : "prod";
  const config = {
    devtool: "source-map",
    entry: {
      ...
      functions: ["./src/functions/one.ts", "./src/functions/two.ts"],
      ...

Then (also in webpack config) I added separate CustomFunctionsMetadataPlugin entries in plugins for each of the files:

...
plugins: [
      new CustomFunctionsMetadataPlugin({
        output: "functions.json",
        input: "./src/functions/one.ts",
      }),
      new CustomFunctionsMetadataPlugin({
        output: "functions.json",
        input: "./src/functions/two.ts",
      }),
...

It builds fine but running in Excel only the functions from the last CustomFunctionsMetadataPlugin plugin entry are visible (in this case those custom functions declared in two.ts).

Is there a way to separate excel custom function declarations into multiple files?

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
Antoine Dahan
  • 574
  • 2
  • 9
  • 23
  • It makes sense to check the `functions.json` content then? Do you see any difference if you build the single file without splitting the source code? – Eugene Astafiev Feb 01 '22 at 22:45
  • @EugeneAstafiev When splitting, the generated `function.json` only contains the functions from the file of the last CustomFunctionMetadataPlugin declared in webpack config. I'm wondering if there is a way to have it pull functions from multiple files and place them all in function.json. The [examples](https://github.com/OfficeDev/Office-Addin-Scripts/blob/master/packages/custom-functions-metadata-plugin/README.md) from Microsoft only have one single file. – Antoine Dahan Feb 03 '22 at 14:51
  • That is question to the webpack, not MS. – Eugene Astafiev Feb 03 '22 at 15:05
  • 1
    I've raised this [here](https://github.com/OfficeDev/Office-Addin-Scripts/issues/681) which is where this change would need to be made. – parched Oct 17 '22 at 01:52

0 Answers0