yushijinhun/three-minifier

Gatsby webpack merging issue

Closed this issue · 4 comments

Gatsby is not exposing it's webpack config, but instead gives you means to extend it. As a result when I add three-minifier using gatsby API the plugin is added LAST to the array of other plugins and resolvers. The error it gives is : "WEBPACK Generating JavaScript bundles failed The 'compilation' argument must be an instance of Compilation".
Versions of node ,three and webpack are correct.
Is there a workaround from the plugin's side that can fix the issue?

I couldn't find the exact webpack config that is used by Gatsby and therefore can't completely replace it without breaking something.

You can use getConfig to obtain the webpack config.

const ThreeMinifierPlugin = require("@yushijinhun/three-minifier-webpack");
const threeMinifier = new ThreeMinifierPlugin();

exports.onCreateWebpackConfig = ({ actions, getConfig }) => {
  const config = getConfig();
  config.plugins = [
    threeMinifier,
    ...config.plugins
  ];
  config.resolve.plugins = [
    threeMinifier.resolver,
    ...config.resolve.plugins
  ];
  actions.replaceWebpackConfig(config);
};

I created a clean gatsby project and added plugin, it works even without putting it on the first place in plugin list, albeit with a lot of warnings.
I believe the problem is somewhere else, and we can close the issue.