Possible to apply custom webpack config just for one particular Netlify Function and not the others?

Hi there,

I’m testing Netlify functions on hrb-test.netlify.app and I have several Netlify Functions built and they work great. However, a Netlify Function that I just added is causing an undesired problem with another Function that was working previously. The new function uses the serverless-mysql package. Unfortunately, it suffers from an open issue from one of it’s dependancies in the mysql package. The issue is that if minification is used to compile it, it breaks, so the workaround is that you must disable minification using a custom webpack.functions.js, which I’ve tacked into my lambda build command and now it works.

That simply looks like this:

module.exports = {
  optimization: { minimize: false }
};

And that solves the problem with the serverless-mysql package from breaking. Great! But, unfortunately, I couldn’t celebrate so fast.

Now, in disabling minification in webpack, this causes another problem with another one of my Netlify Functions which now pushes the total size to 2MB since minification is disabled, which is above the size limit and now this function is no longer available or works.

So, my question is if it is possible to apply the disabling of the minification to only that one specific function that is using the serverless-mysql package and not the others? Any help would be greatly appreciated in doing this.

Here is more background on the core issue that required the disabling of minification:

Actually, reading through the comments of that open issue came up with a workaround that seems to work for me.

I’m posting this here in case it might help others.

Now I’m adding the Terser plugin which performs code minification but preserves the variable names which is the core problem with serverless-mysql breaking under minification.

Here is how my webpack.functions.js file looks like now:

const TerserPlugin = require('terser-webpack-plugin');

module.exports = {
  optimization: { minimizer: [new TerserPlugin({ terserOptions: { mangle: false } })] }
};

And here’s my build command: netlify-lambda build src/lambda --config ./webpack.functions.js

Now it reduces the filesize of my Netlify functions while retaining the variable names. This keeps my other function from becoming too bloated to be able to run and solves the minification issue.

Success!

1 Like