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 bundle size fortawesome #1289

Merged
merged 8 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,22 @@
"ts": "never",
"tsx": "never"
}
]
],
"no-restricted-imports": ["error", {
"patterns": [
{
"group": ["@fortawesome/free-brands-svg-icons/*", "@fortawesome/free-brands-svg-icons"],
"message": "Direct imports from @fortawesome/free-brands-svg-icons is not allowed. Import from src/ib/font_awesome/brands instead."
},
{
"group": ["@fortawesome/pro-regular-svg-icons/*", "@fortawesome/pro-regular-svg-icons"],
"message": "Direct imports from @fortawesome/pro-regular-svg-icons is not allowed. Import from src/lib/font_awesome/regular instead."
},
{
"group": ["@fortawesome/pro-solid-svg-icons/*", "@fortawesome/pro-solid-svg-icons"],
"message": "Direct imports from @fortawesome/pro-solid-svg-icons is not allowed. Import from src/lib/font_awesome/solid instead."
}
]
}]
}
}
2 changes: 1 addition & 1 deletion src/Accordion/Accordion.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { faCreditCard } from '@fortawesome/pro-regular-svg-icons';
import { faCreditCard } from '../font_awesome/regular';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using relative imports; Locally I kept getting

[webpack-cli] ModuleNotFoundError: Module not found: Error: Can't resolve 'src/font_awesome/solid' in '/Users/domschab/Work/rails-server/node_modules/@user-interviews/ui-design-system/lib/Accordion'

When building rs shakapacker

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can look at absolute imports without reexporting this as a nice to have in the follow up

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can address the best course of actions for relative imports in a follow up PR; I was reading up about it and this may be tricky to get done. Adding alias in RS shakapacker config doesn't seem like a good solution

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is DS wired up to respect ts files? I'm assuming it is... but if it only had TSX until now then that could be why its not resolving

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is DS wired up to respect ts files?

I think so; we've had .ts files here for a while. Based on what I was reading, it might seem like webpack/shaka might also have be aware of the correct alias configuration for bundling/resolving modules (which that seems weird to add an alias in shaka config in rs repo). So it may not be enough to specify an alias in .babelrc file in DS repo. Happy to look more into this in a separate PR

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that an error with rails server, or building DS?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rails server; there's no error building DS

import Card from '../Card';

import {
Expand Down
3 changes: 2 additions & 1 deletion src/Accordion/AccordionToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { useAccordionButton } from 'react-bootstrap/AccordionButton';
import AccordionContext from 'react-bootstrap/AccordionContext';

import { faChevronUp } from '../font_awesome/solid';

import './AccordionToggle.scss';
import { faChevronUp } from '@fortawesome/pro-solid-svg-icons';

import { isEventKeyActive } from './utils';

Expand Down
2 changes: 1 addition & 1 deletion src/Alert/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
faExclamationTriangle,
faInfo,
faTimes,
} from '@fortawesome/pro-solid-svg-icons';
} from '../font_awesome/solid';

import './Alert.scss';

Expand Down
4 changes: 2 additions & 2 deletions src/Button/Button.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import * as ComponentStories from './Button.stories';
### Iconography
- Font Awesome library
- We utilize the Regular and Solid Font Awesome icons
- Only use Solid icons on icon-only buttons. import `@fortawesome/pro-solid-svg-icons`
- Use Regular icons for all other buttons. import `@fortawesome/pro-regular-svg-icons`
- Only use Solid icons on icon-only buttons. import relatively from `src/font_awesome/solid`
- Use Regular icons for all other buttons. import relatively from `src/font_awesome/regular`
- Use a leading icon alongside a label if there is a primary action verb (e.g. Edit, Share, Copy)
- Icon-only buttons should only be permitted if
- Space is limited (e.g. too small for text alone)
Expand Down
4 changes: 2 additions & 2 deletions src/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';

import { IconDefinition } from '@fortawesome/fontawesome-svg-core';
import { faFileAlt, faCaretDown, faPaperPlane } from '@fortawesome/pro-regular-svg-icons';
import { faFileAlt, faCaretDown, faPaperPlane } from '../font_awesome/regular';
import {
faGoogle, faFacebook, faLinkedin, faTwitter,
} from '@fortawesome/free-brands-svg-icons';
} from '../font_awesome/brands';
import Button from '.';
import mdx from './Button.mdx';

Expand Down
4 changes: 2 additions & 2 deletions src/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import React, { forwardRef } from 'react';
import classNames from 'classnames';
import { IconDefinition } from '@fortawesome/fontawesome-svg-core';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faSpinnerThird } from '@fortawesome/pro-regular-svg-icons';

import {
Button as RBButton,
type ButtonProps as RBButtonProps,
} from 'react-bootstrap';

import { faSpinnerThird } from '../font_awesome/regular';

import './Button.scss';

export enum ButtonSizes {
Expand Down
2 changes: 1 addition & 1 deletion src/Container/Col.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
type ColProps as ReactBootstrapColProps,
} from 'react-bootstrap';

import { useDeprecationWarning } from 'src/utils';
import { useDeprecationWarning } from '../utils';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually failed for me as well locally so using relative (looks like a new addition that wasn't released yet to rs repo)

[webpack-cli] ModuleNotFoundError: Module not found: Error: Can't resolve 'src/utils' in '/Users/domschab/Work/rails-server/node_modules/@user-interviews/ui-design-system/lib/Container'

When building rs shakapacker

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @jeffbax

(and this is example from a different PR from a couple of days ago that would make a rs build fail if we tried to merge newest DS to rs)

with relative imports to utils / icons in DS, RS build works. The problem here is defining aliases for internal of DS package that will also work with RS build. That could be looked at when we incorporate rollup as a follow on, but the PR in current states works with rs build.


export type ColProps = {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/Container/Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
type ContainerProps as ReactBootstrapContainerProps,
} from 'react-bootstrap';

import { useDeprecationWarning } from 'src/utils';
import { useDeprecationWarning } from '../utils';

export type ContainerProps = {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/Container/Row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
type RowProps as ReactBootstrapRowProps,
} from 'react-bootstrap';

import { useDeprecationWarning } from 'src/utils';
import { useDeprecationWarning } from '../utils';

export type RowProps = {
/**
Expand Down
6 changes: 4 additions & 2 deletions src/CopyToClipboardButton/CopyToClipboardButton.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React, { useState } from 'react';
import classNames from 'classnames';
import { CopyToClipboard } from 'react-copy-to-clipboard';

import { type IconDefinition } from '@fortawesome/fontawesome-svg-core';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faCopy } from '@fortawesome/pro-regular-svg-icons';
import { CopyToClipboard } from 'react-copy-to-clipboard';

import { faCopy } from '../font_awesome/regular';

import TrackedButton from '../TrackedButton';
import Popper from '../Popper';
Expand Down
2 changes: 1 addition & 1 deletion src/DateTimePicker/PickerEnforcedInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import classNames from 'classnames';
import { isValid } from 'date-fns';

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faCalendarAlt } from '@fortawesome/pro-regular-svg-icons';
import { faCalendarAlt } from '../font_awesome/regular';

type PickerEnforcedInputProps = {
disabled?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/Drawer/Drawer.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { useState } from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import {
faEnvelope, faChevronLeft, faChevronRight, faTrash,
} from '@fortawesome/pro-solid-svg-icons';
} from '../font_awesome/solid';
import {
Drawer, DrawerBody, DrawerFooter, DrawerHeader,
} from '.';
Expand Down
2 changes: 1 addition & 1 deletion src/Drawer/DrawerHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { type IconDefinition } from '@fortawesome/fontawesome-svg-core';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import {
faTimes, faCompressAlt, faExpandAlt,
} from '@fortawesome/pro-solid-svg-icons';
} from '../font_awesome/solid';

import './DrawerHeader.scss';

Expand Down
5 changes: 2 additions & 3 deletions src/Dropdown/Dropdown.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React from 'react';

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import {
faEllipsisV, faFileAlt, faChevronDown, faTag, faEnvelope, faTrashAlt,
} from '@fortawesome/pro-regular-svg-icons';

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
} from '../font_awesome/regular';
import {
Dropdown, DropdownDivider, DropdownToggle, DropdownItem, DropdownMenu,
} from '.';
Expand Down
2 changes: 1 addition & 1 deletion src/EmptyState/EmptyState.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import type { Meta, StoryObj } from '@storybook/react';

import { IconDefinition } from '@fortawesome/fontawesome-svg-core';
import { faPlus } from '@fortawesome/pro-regular-svg-icons';
import { faPlus } from '../font_awesome/regular';

import Button from '../Button';

Expand Down
2 changes: 1 addition & 1 deletion src/Flex/Flex.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ReactNode, ElementType, createElement } from 'react';
import classNames from 'classnames';

import { useDeprecationWarning } from 'src/utils';
import { useDeprecationWarning } from '../utils';

import styles from './Flex.module.scss';

Expand Down
2 changes: 1 addition & 1 deletion src/FormGroup/FormGroup.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from 'react';
import { faSearch } from '@fortawesome/pro-solid-svg-icons';

import { FlexContainer } from 'src/FlexContainer';
import { faSearch } from '../font_awesome/solid';
import FormGroup from '.';
import Input from '../Input';
import FormControlLabel from '../FormControlLabel';
Expand Down
2 changes: 1 addition & 1 deletion src/IconButton/IconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
faPencil,
faTimes,
faExpandAlt,
} from '@fortawesome/pro-regular-svg-icons';
} from '../font_awesome/regular';
import Button, { type ButtonProps } from '../Button/Button';

export const IconButtonActions = {
Expand Down
2 changes: 1 addition & 1 deletion src/IconCell/IconCell.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';

import {
faGlobe, faMailbox, faPaperPlane, faStar, faUser,
} from '@fortawesome/pro-regular-svg-icons';
} from '../font_awesome/regular';

import IconCell from '.';
import mdx from './IconCell.mdx';
Expand Down
2 changes: 1 addition & 1 deletion src/IconCell/IconCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import { type IconDefinition } from '@fortawesome/fontawesome-svg-core';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

import { useDeprecationWarning } from 'src/utils';
import { useDeprecationWarning } from '../utils';

import './IconCell.scss';

Expand Down
2 changes: 1 addition & 1 deletion src/LoadingOverlay/LoadingOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import classNames from 'classnames';

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faSpinnerThird } from '@fortawesome/pro-solid-svg-icons';
import { faSpinnerThird } from '../font_awesome/solid';

import './LoadingOverlay.scss';

Expand Down
2 changes: 1 addition & 1 deletion src/Modal/ModalHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import classNames from 'classnames';
import './ModalHeader.scss';

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faExclamationTriangle } from '@fortawesome/pro-solid-svg-icons';
import { faExclamationTriangle } from '../font_awesome/solid';

type ModalHeaderProps = {
children?: React.ReactNode;
Expand Down
2 changes: 1 addition & 1 deletion src/Pill/Pill.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { action } from '@storybook/addon-actions';
import {
faClock, faGiftCard, faGlobe, faMicrophone, faUsers,
} from '@fortawesome/pro-solid-svg-icons';
} from '../font_awesome/solid';

import { Pill, Pills, PILL_COLORS } from '.';
import mdx from './Pill.mdx';
Expand Down
4 changes: 2 additions & 2 deletions src/Pill/Pill.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import classNames from 'classnames';
import { type IconDefinition } from '@fortawesome/pro-solid-svg-icons';
import { type IconDefinition } from '@fortawesome/fontawesome-svg-core';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faTimes } from '@fortawesome/pro-solid-svg-icons';
import { faTimes } from '../font_awesome/solid';

import './Pill.scss';

Expand Down
2 changes: 1 addition & 1 deletion src/ProfileCell/ProfileCell.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { faShieldCheck } from '@fortawesome/pro-solid-svg-icons';
import { faShieldCheck } from '../font_awesome/solid';
import ProfileCell from '.';
import ProfileCellSkeleton from './ProfileCellSkeleton';
import mdx from './ProfileCell.mdx';
Expand Down
2 changes: 1 addition & 1 deletion src/RichTextEditor/RichTextEditorMenuBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
faListOl,
faListUl,
faUnlink,
} from '@fortawesome/pro-regular-svg-icons';
} from '../font_awesome/regular';
import IconButton from '../IconButton';

import { RichTextEditorActions } from './richTextEditorActions';
Expand Down
2 changes: 1 addition & 1 deletion src/Table/Table.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useState } from 'react';

import { faFileAlt, faEllipsisV, faThumbtack } from '@fortawesome/pro-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

import { faFileAlt, faEllipsisV, faThumbtack } from '../font_awesome/solid';
import Button from '../Button';
import Card from '../Card';
import CheckboxButton from '../CheckboxButton';
Expand Down
2 changes: 1 addition & 1 deletion src/Table/TableSortLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faSort } from '@fortawesome/pro-solid-svg-icons';
import { faSort } from '../font_awesome/solid';

import './TableSortLabel.scss';

Expand Down
2 changes: 1 addition & 1 deletion src/Tooltip/Tooltip.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import classNames from 'classnames';

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faQuestionCircle } from '@fortawesome/pro-solid-svg-icons';
import { faQuestionCircle } from '../font_awesome/solid';

import Popper from '../Popper';

Expand Down
2 changes: 1 addition & 1 deletion src/Tooltip/Tooltip.stories.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { action } from '@storybook/addon-actions';

import { faExclamationTriangle } from '@fortawesome/pro-solid-svg-icons';
import { faExclamationTriangle } from '../font_awesome/solid';

import Tooltip from '.';
import mdx from './Tooltip.mdx';
Expand Down
19 changes: 19 additions & 0 deletions src/font_awesome/brands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Keep this eslint-disable here. FontAwesome imports should only be happening
// in this file and nowhere else in the codebase.
//
// Any direct import from '@fortawesome/free-brands-svg-icons' will create bloat in
// our overall bundle size.

/* eslint-disable no-restricted-imports */

import { faGoogle } from '@fortawesome/free-brands-svg-icons/faGoogle';
import { faFacebook } from '@fortawesome/free-brands-svg-icons/faFacebook';
import { faLinkedin } from '@fortawesome/free-brands-svg-icons/faLinkedin';
import { faTwitter } from '@fortawesome/free-brands-svg-icons/faTwitter';

export {
faGoogle,
faFacebook,
faLinkedin,
faTwitter,
};
Loading