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

MiniCssExtractPlugin compatible? #3

Open
eatsjobs opened this issue Dec 12, 2018 · 3 comments
Open

MiniCssExtractPlugin compatible? #3

eatsjobs opened this issue Dec 12, 2018 · 3 comments

Comments

@eatsjobs
Copy link

Hi thanks for you work on this.
did the plugin should work with css chunk and with MiniCssExtractPlugin?
thanks

@MhMadHamster
Copy link
Owner

i did not test with css and minicssplugin tbh so no idea

@hisapy
Copy link

hisapy commented Dec 19, 2018

I just tried this plugin in a project with MiniCssExtractPlugin. The output of the initial css chunk still contain the chunkhash, like main.3ba29441.chunk.css

@hisapy
Copy link

hisapy commented Dec 20, 2018

I hardcoded the following plugin in our react-scripts fork

class ChunkNamesPlugin {
  apply(compiler) {
    compiler.hooks.compilation.tap('ChunkNamesPlugin', compilation => {
      compilation.chunkTemplate.hooks.renderManifest.intercept({
        register(tapInfo) {
          if (tapInfo.name === 'JavascriptModulesPlugin') {
            const originalFn = tapInfo.fn;

            tapInfo.fn = (result, options) => {
              const chunkName = options.chunk.name;

              // Don't mutate options passed to other plugins
              let customOpts = { ...options };

              if (chunkName === 'main' || chunkName === 'vendors~main') {
                customOpts.outputOptions = {
                  ...options.outputOptions,
                  chunkFilename: 'js/[name].chunk.js',
                };

                const hasCss =
                  result[0] &&
                  result[0].identifier.startsWith('mini-css-extract-plugin');

                if (hasCss) {
                  result[0].filenameTemplate = 'css/[name].chunk.css';
                }
              }

              originalFn(result, customOpts);
            };
          }

          return tapInfo;
        },
      });
    });
  }
}

That's how I managed to avoid chunkhash in initial .css chunks. Maybe it can serve as an example to support MiniCssExtractPlugin in this lib.

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

No branches or pull requests

3 participants