简体   繁体   English

如何减少索环中的webpack捆绑包大小?

[英]How to reduce webpack bundle size in grommet?

I'm using Grommet. 我正在使用Grommet。 I've followed the getting started guide and made my first application. 我遵循了入门指南,并做了我的第一个应用程序。 The webpack bundle generated for production is a single JavaScript file that exceeds 1.7 MB and I didn't add anything to the get started example. 用于生产的webpack捆绑包是一个超过1.7 MB的JavaScript文件,我没有在入门示例中添加任何内容。

Is there is a way to reduce this bundle file size or split it into more than one file? 有没有办法减小捆绑文件的大小或将其拆分成多个文件?

Update 更新

I identified two sources of savings. 我确定了两种储蓄来源。 One small and directly related to Grommet, and one larger and related to vendor. 一小部分与Grommet直接相关,一小部分与供应商相关。

Savings
219Kb   Remove use of Card   (my only use of remark-parse and friends)
3.13MB  Remove use of webpack.optimize.CommonsChunkPlugin†

†webpack †的WebPack

// vendor: [ 'grommet'...]
// ...
// new webpack.optimize.CommonsChunkPlugin({
//   name: 'vendor',
//   children: true,
//   minChunks: 2,
//   async: true,
// }),

jsx JSX

// import Card from 'grommet/components/Card'; ... <Card />
import Box from 'grommet/components/Box'; ... <Box />

==== ====

Webpack 2.3.1 'vendor' appears to pull in everything. Webpack 2.3.1的“供应商”似乎可以吸收一切。 I had imported a few Grommet components sparingly into React. 我已经少量地将一些Grommet组件导入了React。

Specifying vendor: [ 'grommet'...] in webpack config resulted in a bundle size of > 3MB. 在webpack配置中指定vendor: [ 'grommet'...] grommet vendor: [ 'grommet'...]导致捆绑包大小> 3MB。

vendor.c119b2da32ae94938692.js 3.15 MB 1 [emitted] [big] vendor

Removing grommet from that array resulted in a size of 429K. 从该阵列中删除索环导致大小为429K。

vendor.0619a5794ef890b54543.js 429 kB 2 [emitted] [big] vendor

The other bundle sizes did not change. 其他捆绑包的大小没有变化。

You are probably importing Grommet like this: 您可能是这样导入Grommet的:

import Grommet from 'grommet';

or 要么

var Grommet =  require('grommet');

or 要么

import { Box, Chart } from 'grommet/components';

This will load the entire Grommet library (including the ~300+ control icons) and then filter it down to whatever you are using. 这将加载整个Grommet库(包括约300多个控件图标),然后将其筛选为所使用的内容。

You can improve that by import each component separately, as in: 您可以通过分别导入每个组件来改进它,如下所示:

import Box from 'grommet/components/Box';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM