Skip to content

Reduce bundle size of parser-html.js#12176

Merged
fisker merged 2 commits intoprettier:mainfrom
sosukesuzuki:reduce-parser-html-size-
Jan 28, 2022
Merged

Reduce bundle size of parser-html.js#12176
fisker merged 2 commits intoprettier:mainfrom
sosukesuzuki:reduce-parser-html-size-

Conversation

@sosukesuzuki
Copy link
Copy Markdown
Contributor

Description

Before:

$ node ./scripts/build/build.mjs --file=parser-html.js --print-size
 Building packages 
parser-html.js..................................................179 kB    DONE  

After:

$ node ./scripts/build/build.mjs --file=parser-html.js --print-size
 Building packages 
parser-html.js..................................................156 kB    DONE  

Checklist

  • I’ve added tests to confirm my change works.
  • (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory).
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.

Try the playground for this PR

@sosukesuzuki sosukesuzuki requested a review from fisker January 27, 2022 17:47
const arrayToMap = require("./array-to-map.js");

const HTML_ELEMENT_ATTRIBUTES = mapObject(htmlElementAttributes, arrayToMap);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you try use html-elements-attributes.evaluate.js as filename to see if the bundle became smaller?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried it in my local but bundle size didn't became smaller.

 Building packages 
parser-html.js..................................................156 kB    DONE  

Copy link
Copy Markdown
Member

@fisker fisker Jan 28, 2022

Choose a reason for hiding this comment

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

Thanks, it's not safe anyway, mapObject use Object.create(null), but turns to JSON will be an normal object

HTML_ELEMENT_ATTRIBUTES.prototype will be truly.


const HTML_TAGS = arrayToMap(htmlTagNames);

module.exports = HTML_TAGS;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here.

@fisker fisker merged commit ff78a94 into prettier:main Jan 28, 2022
@sosukesuzuki sosukesuzuki deleted the reduce-parser-html-size- branch January 28, 2022 03:25
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jan 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants