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

Feature: Disable Extracting Specified CSS Module from Chunks #432

Open
wants to merge 25 commits into
base: master
Choose a base branch
from

Conversation

lsycxyj
Copy link

@lsycxyj lsycxyj commented Jul 20, 2019

This PR contains a:

  • bugfix
  • new feature
  • code refactor
  • test update
  • typo fix
  • metadata update

Motivation / Use-Case

You may disable extracting css modules programmatically by passing a function.

const miniCssExtractPlugin = new MiniCssExtractPlugin({
  disableExtract({ module, isAsync }) {
    // Do whatever you want. Disable by content size for example:
    // return module.content.length < 10 * 1024;
    // Or disable extracting from all async chunks
    return isAsync;
  },
});

Breaking Changes

None

Additional Info

I found #348 doesn't work at all by now and it's not flexible enough, so I made another pull request based on recent master branch.

@lsycxyj
Copy link
Author

lsycxyj commented Jul 20, 2019

Well... the lint problems may be a bit difficult to be fixed...

@lsycxyj lsycxyj changed the title Feature: Disable extracting css from async modules Feature: Disable extracting css from async chunks Jul 21, 2019
@lsycxyj lsycxyj force-pushed the feature/disable_async_20190719 branch from 4d29761 to f9d7df1 Compare July 21, 2019 03:26
@alexander-akait
Copy link
Member

alexander-akait commented Jul 22, 2019

What is use case? Why you need disable async css?, also i think we should solve this in other case, provide developers function shouldBeExtracted(options) { if (something) { return false } return true; }, it is allows solve many cases, not only async, fox example you can keep small css inside js and many other cases

@lsycxyj
Copy link
Author

lsycxyj commented Jul 22, 2019

@evilebottnawi See this comment. I don't need to make extra an request to fetch the css file of its own async js chunk which it has been loaded.

@alexander-akait
Copy link
Member

@lsycxyj please read my comment above, we can implement general solution instead only for one case

@lsycxyj
Copy link
Author

lsycxyj commented Jul 22, 2019

@evilebottnawi For general solution, I think a "shouldBeExtracted" function for all modules would be much better. I can decide whether a css module depending on its information: whether it is an async module, content, file size, and more.

@alexander-akait
Copy link
Member

@lsycxyj yes, feel free to update PR and implement this option 👍

@lsycxyj
Copy link
Author

lsycxyj commented Jul 24, 2019

@evilebottnawi I managed it. Now disableExtract option has been implemented.

README.md Outdated Show resolved Hide resolved
Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here a lot of breaking changes, regressions and very bad code, idea is good, but implementation very bad

@alexander-akait
Copy link
Member

Look here https://github.com/webpack-contrib/mini-css-extract-plugin/blob/master/src/loader.js#L101, just skip module for keeping module in js

@lsycxyj
Copy link
Author

lsycxyj commented Jul 24, 2019

@evilebottnawi Do you mean like my latest commit? (37ce619). I made less code difference.
I'm afraid I don't quite understand how to skip module in https://github.com/webpack-contrib/mini-css-extract-plugin/blob/master/src/loader.js#L101

@lsycxyj lsycxyj changed the title Feature: Disable extracting css from async chunks Feature: Disable Extracting Specified CSS Module from Chunks Jul 24, 2019
@lsycxyj
Copy link
Author

lsycxyj commented Jul 25, 2019

@evilebottnawi Friendly ping

@lsycxyj
Copy link
Author

lsycxyj commented Aug 9, 2019

Hi, @evilebottnawi, Is there anything else need to be improved? I suppose there can't be less code changes to implement this feature.

@alexander-akait
Copy link
Member

In todo, a lot of issues, you can use own branch if need this asap

@lsycxyj lsycxyj closed this Feb 3, 2020
@lsycxyj
Copy link
Author

lsycxyj commented Feb 4, 2020

Merge from latest master, fix bug and reopen

@lsycxyj lsycxyj reopened this Feb 4, 2020
@lsycxyj
Copy link
Author

lsycxyj commented Feb 6, 2020

Known issue: some variables will become "void 0" in some modules after enabling disableExtract in complicated cases, and I don't have any good idea that I can rebuild the modules correctly. Could you do me a favor, please? @evilebottnawi

…sync_20190719

# Conflicts:
#	README.md
#	azure-pipelines.yml
#	package-lock.json
#	package.json
#	src/index.js
#	src/loader.js
#	test/TestCases.test.js
#	test/helpers/getCompiler.js
#	test/helpers/index.js
#	test/manual/webpack.config.js
@codecov
Copy link

codecov bot commented Aug 6, 2020

Codecov Report

Merging #432 (40af212) into master (b146549) will increase coverage by 1.13%.
The diff coverage is 97.91%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #432      +/-   ##
==========================================
+ Coverage   88.55%   89.68%   +1.13%     
==========================================
  Files           5        5              
  Lines         428      475      +47     
  Branches       96      104       +8     
==========================================
+ Hits          379      426      +47     
  Misses         47       47              
  Partials        2        2              
Impacted Files Coverage Δ
src/index.js 89.49% <97.67%> (+1.64%) ⬆️
src/loader.js 90.90% <100.00%> (+1.43%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b146549...40af212. Read the comment docs.

Copy link
Member

@sokra sokra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The functionally seem to be based on rebuilding modules. That's really problematic as it leads to inconsistencies and performance problems. Rebuilding modules should be avoided.

There is already the option to apply mini-css only to some modules via the rule system. I don't think this PR is needed anymore when the isAsync feature is removed.


```javascript
const miniCssExtractPlugin = new MiniCssExtractPlugin({
disableExtract({ module, isAsync }) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name it in positive way e.g. should extract

@lsycxyj
Copy link
Author

lsycxyj commented Aug 7, 2020

The functionally seem to be based on rebuilding modules. That's really problematic as it leads to inconsistencies and performance problems. Rebuilding modules should be avoided.

There is already the option to apply mini-css only to some modules via the rule system. I don't think this PR is needed anymore when the isAsync feature is removed.

@sokra Thank you for your review.

Actually, this feature is originally named "disableAsync". The main purpose of the feature is to find out async modules and disable the extraction programactically.

Then, @evilebottnawi gave me advice that to do it with a function like shouldBeExtracted, and it became "disableExtract".

I do understand it leads to some problems. However, I can't figure out any better way to implement the feature by now. I'm still looking for an alternative way.

@alexander-akait
Copy link
Member

There is already the option to apply mini-css only to some modules via the rule system. I don't think this PR is needed anymore when the isAsync feature is removed.

Why this is unacceptable?

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.

None yet

3 participants