Search code examples
javascriptwebpackreflectionfunction-parameterwebpack-production

How to get original function parameter names in production webpack build


I'm trying to implement something similar to dependency injection, By getting parameter names from a function exposed by a javascript module, something like this:

module.exports = (router,form,query,url) => {

    // Do something with these parameters ...

    return response;
};

I can solve this problem by parsing the string representation of the function. There's already a SO thread for that.

My problem becomes apparent when the code is bundled for production with webpack, all the parameter names get mangled, and the original names are lost.

I couldn't find any option in the webpack config that can help me with that.

Is there a way to do what I want without making the module that exports the function worry about anything related to this problem?


Solution

  • What I'm trying to do is not possible.

    By the time the code gets to the minimizer plugin, it has already been concatenated into a single bundle file.

    Another option is to use uglify-loader, but that only works on module level, so you're left with non-minified code that wraps the actual modules.