Skip to content

[Beta] Update package exports#4624

Merged
thisisdano merged 8 commits into
library--developfrom
jm-beta-update-exports
Apr 18, 2022
Merged

[Beta] Update package exports#4624
thisisdano merged 8 commits into
library--developfrom
jm-beta-update-exports

Conversation

@mejiaj

@mejiaj mejiaj commented Apr 11, 2022

Copy link
Copy Markdown
Contributor

Description

Updated package export paths. Export paths in package.json are updated to reflect the new package structure.

Users can take advantage of updated path exports to avoid unnecessarily long paths to assets in new structure.

Example

// Old
import USWDS from "../node_modules/uswds/src/js/components";
const { accordion } = USWDS;


// With new exports
import accordion from "@uswds/uswds/src/js/components/usa-accordion/src/accordion";

// Alternatively
import accordion from "@uswds/uswds/js/usa-accordion/src/accordion";

Importing CSS

import "@uswds/uswds/css/uswds.css";

Importing images

import us_flag_small from "@uswds/uswds/img/us_flag_small.png";

return (
  …USA banner markup
  <img
    className="usa-banner__header-flag"
    src={ us_flag_small }
    alt="U.S. flag"
  />
);

Additional information

⚠️ No breaking changes unless we follow this recommendation to remove this extra long export. I doubt it's being used, but we should call out anyways.


Before you hit Submit, make sure you’ve done whichever of these applies to you:

  • Follow the 18F Front End Coding Style Guide and Accessibility Guide.
  • Run npm test and make sure the tests for the files you have changed have passed.
  • Run your code through HTML_CodeSniffer and make sure it’s error free.
  • Title your pull request using this format: [Website] - [UI component]: Brief statement describing what this pull request solves.

Comment thread package.json Outdated
Comment thread package.json Outdated
Comment thread package.json
"./js/*": "./packages/*.js",
"./css/*": "./dist/css/*",
"./scss/*": "./dist/scss/*",
"./img/*": "./dist/img/*",

@mejiaj mejiaj Apr 14, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This export "./img/*": "./dist/img/*", allows us to import images in React like so:

// example.js
import us_flag_small from "@uswds/uswds/img/us_flag_small.png";

return (
  …USA banner markup
  <img
    className="usa-banner__header-flag"
    src={ us_flag_small }
    alt="U.S. flag"
  />
);

Comment thread package.json Outdated
"./src/img/*": "./packages/usa-icon/src/img",
"./js/*": "./packages/*.js",
"./css/*": "./dist/css/*",
"./scss/*": "./dist/scss/*",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

⚠️Breaking change

Due to updated paths "./scss/*": "./dist/scss/*" requires includePaths in webpack. Which would mean users would have to eject their app and include the paths in their config.

@mejiaj mejiaj Apr 15, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Needs further testing

I've been able to follow this create-react-app guidance to add some include paths without ejecting app. Results have been mixed.

// .env
SASS_PATH=./node_modules:./node_modules/@uswds:./node_modules/@uswds/uswds/packages
// my-stylesheet.scss
@use "uswds-core" as *;

body {
  background-color: color("green-40v");
}

@mejiaj mejiaj marked this pull request as ready for review April 15, 2022 20:40
@mejiaj mejiaj requested a review from thisisdano April 15, 2022 20:40
@thisisdano thisisdano merged commit 4cb9290 into library--develop Apr 18, 2022
@thisisdano thisisdano deleted the jm-beta-update-exports branch April 18, 2022 06:54
@brunerae brunerae linked an issue Apr 25, 2022 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update Beta package exports

2 participants