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

with-ant-design bundle file is too big #4101

Closed
Shangyunliang opened this issue Apr 3, 2018 · 24 comments
Closed

with-ant-design bundle file is too big #4101

Shangyunliang opened this issue Apr 3, 2018 · 24 comments
Labels
examples Issue was opened via the examples template. good first issue Easy to fix issues, good for newcomers

Comments

@Shangyunliang
Copy link

image

In the with-ant-design example, i think these file too big for production. Is this a bug?

Can we optimize it?

@timneutkens
Copy link
Member

@timneutkens timneutkens added help wanted good first issue Easy to fix issues, good for newcomers labels Apr 3, 2018
@supra28
Copy link

supra28 commented Apr 4, 2018

I think it imports the whole css rather than importing just the css for the components that are used

@xavxyz
Copy link

xavxyz commented Apr 5, 2018

CSS Bundle

server bundle result screenshot

⬆️ Server bundle, with almost no CSS loaded (~500 bytes? 🤔), click to read the tooltip

I think it imports the whole css rather than importing just the css for the components that are used

I believed the same, and it actually imports only what it needs in terms of CSS! 😄

I would guess the style.css file is "that big" because @zeit/next-css plugin SSR feature is a work in progress, see vercel/next-plugins#1

JS Bundle

client bundle screenshot

⬆️ Client bundle, loading only the components specified in the example, click to read the tooltip

The index.js bundle is "that big" cause the example imports some heavy components (code), like the Form or the DatePicker.

These components are super-fully-featured and rely on other packages, like components from https://github.com/react-component/ or depend on moment (one-third of the bundle!)

Try just importing the Button and you'll see a neat difference! 📉

Conclusion

  1. next-bundle-analyzer is dope! 🚀
  2. When next-css is fixed, we shouldn't have to load CSS on the client 👌
  3. antd is a great library, but can cost you in terms of size / dependencies! 👍

@aimeefe
Copy link

aimeefe commented Apr 26, 2018

[
"import",
{
"libraryName": "antd"
}
]

@lifuzhao100
Copy link

lifuzhao100 commented May 1, 2018

@aimeefe can u teach me how config babel-plugin-import with antd.now i got an error
@font-face {
^

SyntaxError: Invalid or unexpected token

@ashinga48
Copy link

@Shangyunliang
Please have a look. @supra28 suggestion, i kept in an example.

## 1. ANT Design imports optimisation ( to reduce build size )
Replace

import { DatePicker, Avatar, Badge } from 'antd';
with

import DatePicker from 'antd/lib/date-picker';
import Avatar from 'antd/lib/avatar';
import Badge from 'antd/lib/badge';

with that build changed from 1.4MB to 560KB

## 2. ANT Design CSS import
Instead statical import of full css like this

import stylesheet from 'antd/dist/antd.min.css';
Use

import stylesheet from 'antd/lib/style/index.css'
import Badge_CSS from 'antd/lib/badge/style/index.css'

Example File

https://github.com/ashinga48/Fifi-NextJS-ANT-Design-Redux-Styled-JSX-with-SCSS/blob/master/pages/index.js

Hope it helps

@supra28
Copy link

supra28 commented May 12, 2018

@ashinga48 babel-plugin-import from ant-design does those things automatically.
Docs

@ladieman217
Copy link

@ashinga48 didn't work at all

@Enalmada
Copy link
Contributor

Note there is some information in this thread about getting modular ant design.

@kvedantmahajan
Copy link

Webpack in CRA builds add to +219kb to initial chunk. Whereas importing manual way adds +12 i.e. becomes +231kb

@qaiser110
Copy link

qaiser110 commented Jan 23, 2019

I've created src/client/icons.js at the root. In this file I have all the antd icons that I need like so:

export { default as SwapOutline } from '@ant-design/icons/lib/outline/SwapOutline';
export { default as UploadOutline } from '@ant-design/icons/lib/outline/UploadOutline';

And I've set the absolute imports in next.config.js:

const path = require('path')

module.exports = {
  webpack: function(config, options) {
    config.resolve.alias['@ant-design/icons/lib/dist$'] = path.join(__dirname, 'src/client/icons.js')
    return config
  },
}

Works for me, and I don't see the icons/dist in bundle analyzer. The bundle size is now reduced by 500k

@mssaisandeep
Copy link

Hello,

From antd 3.5 version. when I try to install npm. I am observing "@antdesign" package in nodemodules. When I try to build (npm build which uses webpack) for production and analyze the build, I am getting 2MB for that @antdesign package. Is there anyone facing the same issue?

Note: I have used Babel-Import-Plugin and added the following thing as a configuration in webpack:

plugins: [
            ['import', { libraryName: "antd", libraryDirectory: "lib", style: "css" }],
          ],

I tried different syntaxes using Babel-Import-Plugin (BTW, latest version) but couldn't able to reduce the production build.

Please help me in figuring it out.

@mssaisandeep
Copy link

Hello,

From antd 3.5 version. when I try to install npm. I am observing "@antdesign" package in nodemodules. When I try to build (npm build which uses webpack) for production and analyze the build, I am getting 2MB for that @antdesign package. Is there anyone facing the same issue?

Note: I have used Babel-Import-Plugin and added the following thing as a configuration in webpack:

plugins: [
            ['import', { libraryName: "antd", libraryDirectory: "lib", style: "css" }],
          ],

I tried different syntaxes using Babel-Import-Plugin (BTW, latest version) but couldn't able to reduce the production build.

Please help me in figuring it out.

I am not even using any @antddesign icons. I am just using few antd components which are also showing as separate in bundle analyzer. Please find the screenshot

image

@mssaisandeep
Copy link

Hello,
From antd 3.5 version. when I try to install npm. I am observing "@antdesign" package in nodemodules. When I try to build (npm build which uses webpack) for production and analyze the build, I am getting 2MB for that @antdesign package. Is there anyone facing the same issue?
Note: I have used Babel-Import-Plugin and added the following thing as a configuration in webpack:

plugins: [
            ['import', { libraryName: "antd", libraryDirectory: "lib", style: "css" }],
          ],

I tried different syntaxes using Babel-Import-Plugin (BTW, latest version) but couldn't able to reduce the production build.
Please help me in figuring it out.

I am not even using any @antddesign icons. I am just using few antd components which are also showing as separate in bundle analyzer. Please find the screenshot

image

(Or)
Is there any way that I can exclude @ant-design package from production build? I am using web pack to bundle. Please please help me.

@poorel
Copy link

poorel commented Mar 7, 2019

您好,
来自antd 3.5版本。当我尝试安装npm时。我正在观察nodemodules中的 “ @antdesign ”包。当我尝试构建(使用webpack的npm build)进行生产并分析构建时,我获得了2MB的@antdesign包。有没有人面临同样的问题?
注意:我使用了Babel-Import-Plugin并在webpack中添加了以下内容作为配置:

plugins: [
            ['import', { libraryName: "antd", libraryDirectory: "lib", style: "css" }],
          ],

我使用Babel-Import-Plugin(BTW,最新版本)尝试了不同的语法,但无法减少生产构建。
请帮我搞清楚。

我甚至没有使用任何@antddesign图标。我只是使用很少的antd组件,它们也在bundle分析器中显示为独立的。请找截图
图片

(或)
有什么方法可以从生产版本中排除@ ant-design包吗?我正在使用网络包捆绑。请帮帮我。

Hello,
From antd 3.5 version. when I try to install npm. I am observing "@antdesign" package in nodemodules. When I try to build (npm build which uses webpack) for production and analyze the build, I am getting 2MB for that @antdesign package. Is there anyone facing the same issue?
Note: I have used Babel-Import-Plugin and added the following thing as a configuration in webpack:

plugins: [
            ['import', { libraryName: "antd", libraryDirectory: "lib", style: "css" }],
          ],

I tried different syntaxes using Babel-Import-Plugin (BTW, latest version) but couldn't able to reduce the production build.
Please help me in figuring it out.

I am not even using any @antddesign icons. I am just using few antd components which are also showing as separate in bundle analyzer. Please find the screenshot
image

(Or)
Is there any way that I can exclude @ant-design package from production build? I am using web pack to bundle. Please please help me.

me too.I have the same problem. ask for help.

@stephankaag
Copy link

stephankaag commented Mar 7, 2019

See: ant-design/ant-design#12011
Workaround until fixed (more or less the same as @qaiser110's): ant-design/ant-design#12011 (comment)

@timneutkens timneutkens added the examples Issue was opened via the examples template. label Mar 9, 2019
@blooddrunk
Copy link

blooddrunk commented Aug 18, 2019

I'm using the config from with-ant-design-less example, but the client bundle size is too big even for a page with only a single Button in it, could this be an ant-design specific problem?

微信截图_20190818123744

Why ismoment.js bundled for a Button component?

@typeofweb
Copy link
Contributor

I managed to reduce the bundle size by adding 2 lines to my next.config.js:

config.resolve.alias['@ant-design/icons/lib/dist$'] = path.join(__dirname, 'icons.js')
config.plugins.push(new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),)

@janlukasschroeder

This comment has been minimized.

@timneutkens
Copy link
Member

@janlukasschroeder that looks like a config for cra which is different from Next.js.

@luisgserrano
Copy link

@mmiszy How do you know which icons you need to import if you're using, e.g the pagination component from antd?

@simjoeweb
Copy link

If you want to remove unused momentjs locales:

const MomentLocalesPlugin = require('moment-locales-webpack-plugin');

module.exports = {
  webpack: function(config, options) {
    config.plugins.push(new MomentLocalesPlugin())
    return config
  },
}

Check out: https://www.npmjs.com/package/moment-locales-webpack-plugin

freedomlang added a commit to freedomlang/kiri-frontend that referenced this issue Jan 8, 2020
Change according to issue in next.js, no side effect yet.

vercel/next.js#4101 (comment)
@Timer
Copy link
Member

Timer commented Jan 21, 2020

Duplicate of #9830

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
examples Issue was opened via the examples template. good first issue Easy to fix issues, good for newcomers
Projects
None yet
Development

No branches or pull requests