Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove webpack imports #14

Merged
merged 1 commit into from
Oct 31, 2021
Merged

Remove webpack imports #14

merged 1 commit into from
Oct 31, 2021

Conversation

milan338
Copy link
Contributor

@milan338 milan338 commented Oct 23, 2021

In Next.js, webpack itself is bundled together with Next, and through this, plugins used appear to be unable to require webpack from node_modules. However, webpack 5 exposes compiler.webpack to plugins, meaning webpack imports can be circumvented. This PR does not change any logic, rather it just utilises this new hook that enables usage with Next. An example Next.js config:

const ThreeMinifierPlugin = require('@yushijinhun/three-minifier-webpack');

module.exports = {
    webpack: (config, { isServer, dev }) => {
        if (!isServer && !dev) {
            config.cache = false;
            const threeMinifier = new ThreeMinifierPlugin();
            config.plugins.unshift(threeMinifier);
            config.resolve.plugins.unshift(threeMinifier.resolver);
        }
        return config;
    },
};

@yushijinhun yushijinhun merged commit c40dd52 into yushijinhun:master Oct 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants