Skip to content

Make moment.js tree-shakable by moving ConfigConsumerProps to own file (v1) #3524

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

Merged
merged 1 commit into from
Jan 14, 2021

Conversation

lukaw3d
Copy link

@lukaw3d lukaw3d commented Jan 12, 2021

This is a ...

  • New feature
  • Bug fix
  • Site / document update
  • Component style update
  • TypeScript definition update
  • Refactoring
  • Code style optimization
  • Branch merge
  • Other (about what?): import module size

What's the background?

  1. Describe the source of requirement.

If an app only wants to import some components, the import package size should be small. e.g.

// using babel-plugin-import in babelrc:
["import", { "libraryName": "ant-design-vue", "libraryDirectory": "es", "style": "css" }]

// only importing some components in src/main.js:
import { Badge, Popconfirm, Table } from 'ant-design-vue';
console.log(Badge);

// run
npx vue-cli-service build --report --mode production src/main.js

But this creates a 400KB bundle 😨 with most of it being moment.js
bundle size report

  1. Resolve what problem.

Badge imports moment.js this way:

So by moving ConfigConsumerProps out of components/config-provider/index.jsx, moment.js will not be imported and now bundle takes only 80KB.

(moment.js will still be imported if e.g. import { ConfigProvider, Calendar } from 'ant-design-vue';).

What's the effect?

  1. Does this PR affect user? Which part will be affected?

If user imports only a few components, their tree-shaked bundle will not include moment.js, reducing their bundle size

   File                         Size                             Gzipped

-  dist/js/app.93a8b94c.js      449.68 KiB                       134.98 KiB
+  dist/js/app.98dd1930.js      80.62 KiB                        27.03 KiB
   dist/css/app.1e590c7a.css    40.28 KiB                        4.88 KiB
  1. What will say in changelog?

Make moment.js tree-shakable

  1. Does this PR contains potential break change or other risk?

No

Changelog description (Optional if not new feature)

  1. English description

Make moment.js tree-shakable

  1. Chinese description (optional)

Self Check before Merge

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

@tangjinzhou tangjinzhou merged commit 1e28146 into vueComponent:master Jan 14, 2021
@ekoeryanto
Copy link

using moment as deps in browser is good choice 🤣

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 24, 2022
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.

3 participants