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

Lazy load autoprefixer module #5019

Closed
wants to merge 1 commit into from

Conversation

ybiquitous
Copy link
Member

This change is based on my patch on #4971 (comment).
This mainly lazy-loads the autoprefixer module in lib/utils/isAutoprefixable.js.

Which issue, if any, is this issue related to?

Maybe fix #4971

Is there anything in the PR that needs further explanation?

I don't know how to get an effective benchmark for this change. Could you lease help if you have any good ideas?

const possiblePrefixableValues =
(prefixes.remove[prop.toLowerCase()] && prefixes.remove[prop.toLowerCase()].values) || false;
const remove = prefixes().remove[prop.toLowerCase()];
const possiblePrefixableValues = (remove && remove.values) || false;
Copy link
Member Author

Choose a reason for hiding this comment

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

[note] Fixed duplication of prefixes.remove[prop.toLowerCase()].

Copy link
Member

@jeddy3 jeddy3 left a comment

Choose a reason for hiding this comment

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

I don't know how to get an effective benchmark for this change. Could you lease help if you have any good ideas?

I don't know either, I'm afraid.

Code looks good, though.

@hudochenkov
Copy link
Member

isAutoprefixable.js is only used in -no-vendor-prefix rules. We lazy load all rules, and load only rules, which are in the config. Is this change is needed? Autoprefixer will be loaded anyway if it's needed. And it won't be loaded if not needed (no affected rule is enabled).

@ybiquitous
Copy link
Member Author

@hudochenkov Thanks for your comment. Surely, I also think we should avoid the hack on this PR if possible (to make the code simple).

But, when I examine whether lazy-loading autoprefixer works on the master branch, I find it does not. Please check it out below:

  1. Output the log when autoprefixer is loaded as follows:
--- a/lib/utils/isAutoprefixable.js
+++ b/lib/utils/isAutoprefixable.js
@@ -1,6 +1,7 @@
 'use strict';
 
 const autoprefixer = require('autoprefixer');
+console.log("autoprefixer loaded!!!")
 const Browsers = require('autoprefixer/lib/browsers');
 const Prefixes = require('autoprefixer/lib/prefixes');
 
  1. Prepare a tested CSS file and .stylelintrc.json as follows:
/* a.css */
@-webkit-keyframes { 0% { top: 0; } }
{
  "rules": {
    "at-rule-no-vendor-prefix": null
  }
}
  1. Run stylelint:
$ bin/stylelint.js a.css --no-cache
autoprefixer loaded!!!
  1. Remove at-rule-no-vendor-prefix from .stylelintrc.json:
{
  "rules": {
  }
}
  1. Run stylelint again:
$ bin/stylelint.js a.css --no-cache

Perhaps, may this be another kind of bug?

@hudochenkov
Copy link
Member

Do you think we can find why it is loaded, when it shouldn't and try to fix that?

@ybiquitous
Copy link
Member Author

I'm not sure the following patch is correct, but it can prevent loading a rule module that has null:

--- a/lib/normalizeAllRuleSettings.js
+++ b/lib/normalizeAllRuleSettings.js
@@ -20,6 +20,10 @@ function normalizeAllRuleSettings(config) {
 	Object.keys(config.rules).forEach((ruleName) => {
 		const rawRuleSettings = _.get(config, ['rules', ruleName]);
 
+		if (rawRuleSettings === null) {
+			return;
+		}
+
 		const rule = rules[ruleName] || _.get(config, ['pluginFunctions', ruleName]);
 
 		if (!rule) {

const rawRuleSettings = _.get(config, ['rules', ruleName]);

@jeddy3 jeddy3 mentioned this pull request Jan 11, 2021
6 tasks
@jeddy3 jeddy3 closed this May 19, 2021
@jeddy3 jeddy3 deleted the lazy-load-autoprefixer-module branch May 19, 2021 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Fix slow autoprefixer calls in *-no-vendor-prefix
3 participants