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

Reduce JS parsers bundle size #12156

Merged
merged 3 commits into from
Jan 26, 2022

Conversation

sosukesuzuki
Copy link
Member

@sosukesuzuki sosukesuzuki commented Jan 26, 2022

Description

The bundle size of each JS parser will be reduced by about 50kb.

main:

$ node ./scripts/build/build.mjs --print-size
 Building packages 
index.js.......................................................1.63 MB    DONE  
doc.js..........................................................177 kB    DONE  
standalone.js...................................................529 kB    DONE  
bin-prettier.js.................................................487 kB    DONE  
third-party.js..................................................305 kB    DONE  
parser-babel.js.....................................390 kB, esm 390 kB    DONE  
parser-flow.js....................................2.12 MB, esm 2.12 MB    DONE  
parser-typescript.js..............................3.57 MB, esm 3.57 MB    DONE  
parser-espree.js....................................252 kB, esm 251 kB    DONE  
parser-meriyah.js...................................255 kB, esm 254 kB    DONE  
parser-angular.js...................................111 kB, esm 110 kB    DONE  
parser-postcss.js...............................................237 kB    DONE  
parser-graphql.js.................................43.7 kB, esm 43.2 kB    DONE  
parser-markdown.js..................................173 kB, esm 173 kB    DONE  
parser-glimmer.js...................................193 kB, esm 192 kB    DONE  
parser-html.js......................................179 kB, esm 179 kB    DONE  
parser-yaml.js......................................142 kB, esm 141 kB    DONE  

pr:

$ node ./scripts/build/build.mjs --print-size
 Building packages 
index.js.......................................................1.63 MB    DONE  
doc.js..........................................................177 kB    DONE  
standalone.js...................................................529 kB    DONE  
bin-prettier.js.................................................487 kB    DONE  
third-party.js..................................................305 kB    DONE  
parser-babel.js.....................................338 kB, esm 337 kB    DONE  
parser-flow.js....................................2.07 MB, esm 2.07 MB    DONE  
parser-typescript.js..............................3.52 MB, esm 3.52 MB    DONE  
parser-espree.js....................................199 kB, esm 199 kB    DONE  
parser-meriyah.js...................................202 kB, esm 201 kB    DONE  
parser-angular.js...................................111 kB, esm 110 kB    DONE  
parser-postcss.js...............................................237 kB    DONE  
parser-graphql.js.................................43.7 kB, esm 43.2 kB    DONE  
parser-markdown.js..................................173 kB, esm 173 kB    DONE  
parser-glimmer.js...................................193 kB, esm 192 kB    DONE  
parser-html.js......................................179 kB, esm 179 kB    DONE  
parser-yaml.js......................................142 kB, esm 141 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

@fisker
Copy link
Member

fisker commented Jan 26, 2022

I guess because they both used in parser and printer?

@fisker
Copy link
Member

fisker commented Jan 26, 2022

Move utils.js to utils/index.js?

@sosukesuzuki
Copy link
Member Author

Move utils.js to utils/index.js?

Yes, I was going to do that.

@fisker
Copy link
Member

fisker commented Jan 26, 2022

Why esm size of parser-postcss.js didn't display? bundler: "webpack" still there? Yes, confirmed, please remove that.

@sosukesuzuki
Copy link
Member Author

Why esm size of parser-postcss.js didn't display?

Before, parser-postcss was bundled by webpack, right? This is probably a remnant of that.

@fisker
Copy link
Member

fisker commented Jan 26, 2022

Extact utils to one function is good, but it's easy to trap into circular dependency

@sosukesuzuki
Copy link
Member Author

Yeah, we need to be careful. Let's find an ESLint rule that can detect it?
(Ideally, Tree Shaking for CJS would be enabled so that we don't have to make such a change.)

@sosukesuzuki sosukesuzuki marked this pull request as ready for review January 26, 2022 13:11
@sosukesuzuki sosukesuzuki merged commit d13feed into prettier:main Jan 26, 2022
@sosukesuzuki sosukesuzuki deleted the reduce-js-parser-bundle-size branch January 26, 2022 14:29
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 27, 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