question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[v5] remove `es` dir for better import

See original GitHub issue

What problem does this feature solve?

Since we want to remove lib and focus on ESM only, it is better remove es dir.

Then we can:

import Button from 'antd/button';

instead of:

import Button from 'antd/es/button';

and have a better tree shaking experience.

What does the proposed API look like?

import Button from 'antd/button';

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
afc163commented, Jul 6, 2022

Why not import { Button } from 'antd'; ?

1reaction
izhoutengcommented, Jul 16, 2022

关于你说的这个问题,我深表理解。

题主之所以不喜欢 import { Button } from 'antd' 的语法,一个重要的原因,是因为这样 tree shaking 体验很差。

Vite 中,像上面这样简写的解构导入,会在打包时让 Rollup 去分析整个 antd 包,从而极大的拖慢打包速度。

若改成 import Button from 'antd/es/button',则打包速度可以飞跃提升。

但这种写法,实在是很啰嗦,好在,有一个插件 vite-plugin-imp,可以帮我们自动转换这种写法,并自动引入样式。

其实它就是 babel-plugin-importVite 版,给你参考一下我的配置,希望对你有帮助。

  plugins: [
    {
      ...styleImport({
        resolves: [
          AntdResolve()
        ]
      }),
      apply: 'serve'
    },
    {
      ...vitePluginImp({
        libList: [
          {
            libName: 'antd',
            style (name) {
              return `antd/es/${name}/style/index.js`
            }
          },
          { libName: 'lodash-es', libDirectory: '' },
          { libName: '@ant-design/icons', libDirectory: 'es/icons', camel2DashComponentName: false }
        ]
      }),
      apply: 'build'
    }
  ],

另外,这个问题其实并不关 antd 的事,删除 lib 目录只留 es 目录更是duck不必。

Read more comments on GitHub >

github_iconTop Results From Across the Web

New Features v5 and Migration from v4 - React Suite
For better accessibility, we decided to prefer SVG Icon. And can be well compatible with third-party icon resources. import GearIcon from '@rsuite/icons ...
Read more >
V4 to V5 - Ant Design
CSS-in-JS itself has the ability to import on demand, and plugin support is no longer required. Umi users can remove related configurations.
Read more >
Migrating to v5: getting started - Material UI - MUI
This guide explains how and why to migrate from Material UI v4 to v5.
Read more >
v5 used to include polyfills for node.js core modules by default
Module not found: Error: You attempted to import ... If no - Then remove the package and find an alternative package better suited....
Read more >
Instead change the require of index.js, to a dynamic import ...
and istead of writing require('chalk') in js file change it to import ... of ES Module /Users/myname/Documents/mydir/anotherdir/my-project/ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found