Skip to content
This repository was archived by the owner on Dec 25, 2018. It is now read-only.

problem with ExtractTextPlugin filename #85

Closed
t47io opened this issue Feb 27, 2017 · 8 comments
Closed

problem with ExtractTextPlugin filename #85

t47io opened this issue Feb 27, 2017 · 8 comments

Comments

@t47io
Copy link
Contributor

t47io commented Feb 27, 2017

Hi, I have seen a problem with PurifyCSSPlugin under production mode. Here is my code:

    new ExtractTextPlugin({
      filename: `${DEBUG ? '[name]-[hash:8]' : '[chunkhash:8].min'}.css`,
      allChunks: true,
    }),
    new PurifyCSSPlugin({
      paths: glob.sync(`${rootPath}/app/**/*.{jsx,json,scss}`),
      styleExtensions: ['.css', '.scss'],
      moduleExtensions: ['.html'],
      purifyOptions: {
        minify: !DEBUG,
        info: !DEBUG,
        rejected: true,
      },
      verbose: true,
    }),

This works perfectly fine when DEBUG=true, and I can see the verbose in console like:

Assets to purify: main-843f0e2c.min.css
Files to search for used rules: file1, file2, file3, ...
##################################
PurifyCSS has reduced the file size by ~10.0%
##################################
This function took:  411 ms
##################################
Rejected selectors:
css1
css2
css3
...
##################################

However, when DEBUG=false, it failed to match any assets:

Assets to purify: 

That's all! So I have narrowed down the problem is actually in my ExtractTextPlugin up there. So basically I learned this:

    new ExtractTextPlugin({
      filename: '[name].css', // this HAS TO START WITH '[name]'
      allChunks: true,
    }),

Is this a desired behavior?

@bebraw
Copy link
Contributor

bebraw commented Feb 27, 2017

Hi,

There's something going on. It has been designed to work after ExtractTextPlugin.

Could you set up a tiny project to study?

@t47io
Copy link
Contributor Author

t47io commented Feb 27, 2017

@bebraw here, src/index.js line 35:

              const assetsToPurify = search.assets(
                compilation.assets, options.styleExtensions
              ).filter(
                asset => asset.name.indexOf(chunkName) >= 0
              );

Basically it demands chunkName to be present in filename. I wonder if my request for being able to use '[chunkhash].min.css' in ExtractTextPlugin is a reasonable practice to you.

@bebraw
Copy link
Contributor

bebraw commented Feb 27, 2017

Ok, if you could PR a fix, that would be great.

@t47io
Copy link
Contributor Author

t47io commented Feb 27, 2017

Well I'm afraid not. This piece of code has been in there for a long time (written by you initially, see 1f67894), and I'm not entirely sure about how important it is to keep the plugin working.

@bebraw
Copy link
Contributor

bebraw commented Feb 27, 2017

Looks like it comes from compilation.chunks. It's some corner case the logic is missing.

I might have some proper time for this in a few weeks.

@t47io
Copy link
Contributor Author

t47io commented Feb 28, 2017

@bebraw How about this? Instead of filtering against name, use files:

Line 33 of src/index.js

          compilation.chunks.forEach(
            ({ name: chunkName, files, modules }) => {
              const assetsToPurify = search.assets(
                compilation.assets, options.styleExtensions
              ).filter(
                asset => files.indexOf(asset.name) >= 0
              );
              ...      

Please advice for testing.

@bebraw
Copy link
Contributor

bebraw commented Feb 28, 2017

@t47io Great start. I added a couple of comments to the PR.

@bebraw
Copy link
Contributor

bebraw commented Mar 1, 2017

I think we solved this. Thanks for the PR.

@bebraw bebraw closed this as completed Mar 1, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants