-
Notifications
You must be signed in to change notification settings - Fork 377
feat(rollup): create unified react-core dist #3971
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
Changes from all commits
61be955
de73321
e4a5c28
04d5b3f
9fcb11d
9733847
c3270a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ coverage | |
| **/Generated | ||
| **/build | ||
| css | ||
| packages/react-docs/static | ||
|
|
||
| # package managers | ||
| yarn-error.log | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import resolve from '@rollup/plugin-node-resolve'; | ||
| import commonjs from '@rollup/plugin-commonjs'; | ||
| import scss from 'rollup-plugin-scss'; | ||
| import replace from '@rollup/plugin-replace'; | ||
| import { terser } from 'rollup-plugin-terser'; | ||
|
|
||
| const isProduction = process.env.IS_PRODUCTION; | ||
|
|
||
| module.exports = { | ||
| input: 'dist/esm/index.js', | ||
| output: { | ||
| file: `dist/umd/react-core${isProduction ? '.min' : ''}.js`, | ||
| format: 'umd', | ||
| name: 'PatternFlyReact', | ||
| globals: { | ||
| react: 'React', | ||
| 'react-dom': 'ReactDOM', | ||
| 'prop-types': 'PropTypes' | ||
| } | ||
| }, | ||
| external: ['react', 'react-dom', 'prop-types'], | ||
| plugins: [ | ||
| replace({ | ||
| 'process.env.NODE_ENV': `'${isProduction ? 'production' : 'development'}'` | ||
| }), | ||
| resolve(), | ||
| commonjs(), | ||
| scss(), | ||
| isProduction && terser() | ||
| ] | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import * as React from 'react'; | ||
|
|
||
| interface AlertContext { | ||
| title: React.ReactNode; | ||
| variantLabel?: string; | ||
| } | ||
|
|
||
| export const AlertContext = React.createContext<AlertContext>(null); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| export * from './Alert'; | ||
| export * from './AlertContext'; | ||
| export * from './AlertActionCloseButton'; | ||
| export * from './AlertActionLink'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import * as React from 'react'; | ||
|
|
||
| export const ApplicationLauncherContext = React.createContext({ | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| onFavorite: (itemId: string, isFavorite: boolean) => {} | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,11 +3,10 @@ import { css } from '@patternfly/react-styles'; | |
| import styles from '@patternfly/react-styles/css/components/AppLauncher/app-launcher'; | ||
| import { DropdownItem, DropdownItemProps } from '../Dropdown'; | ||
| import { ApplicationLauncherContent } from './ApplicationLauncherContent'; | ||
| import { ApplicationLauncherContext } from './ApplicationLauncher'; | ||
| import { ApplicationLauncherContext } from './ApplicationLauncherContext'; | ||
| import { ApplicationLauncherItemContext } from './ApplicationLauncherItemContext'; | ||
| import StarIcon from '@patternfly/react-icons/dist/js/icons/star-icon'; | ||
|
|
||
| export const ApplicationLauncherItemContext = React.createContext({ isExternal: false, icon: null }); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't removing an export be a breaking change? I believe it's ok to add ApplicationLauncherItemContext.ts , but perhaps remove this in v4?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! I've reexported it in the |
||
|
|
||
| export interface ApplicationLauncherItemProps { | ||
| /** Icon rendered before the text */ | ||
| icon?: React.ReactNode; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import * as React from 'react'; | ||
|
|
||
| export const ApplicationLauncherItemContext = React.createContext({ isExternal: false, icon: null }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| 'use strict'; | ||
|
|
||
| const e = React.createElement; | ||
|
|
||
| class LikeButton extends React.Component { | ||
| constructor(props) { | ||
| super(props); | ||
| this.state = { liked: false }; | ||
| } | ||
|
|
||
| render() { | ||
| if (this.state.liked) { | ||
| return e(PatternFlyReact.Alert, { | ||
| title: ' Great success', | ||
| children: 'You liked this', | ||
| variant: 'success' | ||
| }); | ||
| } | ||
|
|
||
| return e( | ||
| PatternFlyReact.Button, | ||
| { onClick: () => this.setState({ liked: true }) }, | ||
| 'Like' | ||
| ); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| const domContainer = document.querySelector('#react-root'); | ||
| ReactDOM.render(e(LikeButton), domContainer); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en-us"> | ||
| <head> | ||
| <link rel="stylesheet" href="https://unpkg.com/@patternfly/patternfly@2/patternfly.css" crossorigin /> | ||
| <meta charset="utf-8"/> | ||
| </head> | ||
| <body> | ||
| <h1 class="pf-c-title pf-m-2xl">PatternFly-React UMD Build</h1> | ||
| <p> | ||
| UMD build allow for you to quickly get started using <a href="">@patternfly/react-core.</a> | ||
| If you care about how this is accomplished, it's highly recommended to read | ||
| <a href="https://reactjs.org/docs/add-react-to-a-website.html#add-react-in-one-minute">React's getting started with UMD guide</a> before returning here since. | ||
| This guide uses React's guide as a base. | ||
| </p> | ||
| <h2 class="pf-c-title pf-m-2xl">1. Write HTML</h2> | ||
| <p> | ||
| Create a container to inject React components into. | ||
| <pre> | ||
| <div id="react-root">Inject in here</div> | ||
| </pre> | ||
| </p> | ||
| <h2 class="pf-c-title pf-m-2xl">2. Include JS</h2> | ||
| <p> | ||
| PatternFly React depends on React and PropTypes. Add these to the bottom of the <body> tag on your page: | ||
| <pre> | ||
| <script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script> | ||
| <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script> | ||
| <script src="https://unpkg.com/prop-types@15.6/prop-types.js" crossorigin></script> | ||
| <script src="https://unpkg.com/@patternfly/react-core@3/dist/umd/react-core.umd.js"></script> | ||
| <script src="like-button.js"></script> | ||
| </pre> | ||
|
|
||
| @patternfly/react-core exposes a "PatternFlyReact" object for use in your like-button.js. Populate your like-button.js with something like: | ||
| <pre> | ||
| 'use strict'; | ||
|
|
||
| const e = React.createElement; | ||
|
|
||
| class LikeButton extends React.Component { | ||
| constructor(props) { | ||
| super(props); | ||
| this.state = { liked: false }; | ||
| } | ||
|
|
||
| render() { | ||
| if (this.state.liked) { | ||
| return e(PatternFlyReact.Alert, { | ||
| title: ' Great success', | ||
| children: 'You liked this', | ||
| variant: 'success' | ||
| }); | ||
| } | ||
|
|
||
| return e( | ||
| PatternFlyReact.Button, | ||
| { onClick: () => this.setState({ liked: true }) }, | ||
| 'Like' | ||
| ); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| const domContainer = document.querySelector('#react-root'); | ||
| ReactDOM.render(e(LikeButton), domContainer); | ||
| </pre> | ||
| </p> | ||
| <h2 class="pf-c-title pf-m-2xl">3. (Optional) Include styles</h2> | ||
| <p> | ||
| You have to include <b>ALL</b> our PatternFly styles. There's two ways to do this: | ||
| <pre> | ||
| <link rel="stylesheet" href="https://unpkg.com/@patternfly/patternfly@2/patternfly.css" crossorigin /> | ||
| </pre> | ||
| OR | ||
| <pre> | ||
| <link rel="stylesheet" href="https://unpkg.com/@patternfly/react-core@3/dist/styles/base.css" crossorigin /> | ||
| <link rel="stylesheet" href="https://unpkg.com/@patternfly/react-core@3/dist/react-core.umd.css" crossorigin /> | ||
| </pre> | ||
| </p> | ||
| <h2 class="pf-c-title pf-m-2xl">4. Don't do this in production</h2> | ||
| <p> | ||
| This implementation is very bloated. | ||
| ALL of React, ReactDOM, PropTypes (which you don't need in production...), and PatternFly (including CSS and fonts) are included which takes 912KB <i>after</i> being gzipped. | ||
| Even when minified, they take 520Kb <i>after</i> being gzipped. | ||
| Also, you probably want to be able to use JSX. | ||
| To enable using JSX, treeshaking, and other modern JS tools PatternFly recommendeds consumption using <a href="https://github.com/patternfly/patternfly-react-seed">Webpack.</a> | ||
| It's as simple as cloning <a href="https://github.com/patternfly/patternfly-react-seed">our seed repo</a> and running 2 commands! | ||
| </p> | ||
| <p> | ||
| This page serves as an example of how to do this. Checkout the like button below! | ||
| </p> | ||
| <div id="react-root">Inject like button here</div> | ||
| <script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script> | ||
| <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script> | ||
| <script src="https://unpkg.com/prop-types@15.6/prop-types.js" crossorigin></script> | ||
| <script src="https://unpkg.com/@patternfly/react-core@3/dist/umd/react-core.umd.js"></script> | ||
| <script src="like-button.js"></script> | ||
| </body> | ||
| </html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't you remove prop-types references in another PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but
prop-typesare still generated from thetypescript-to-proptypesplugin. It seemed good to include these in our UMD bundle because there's no type support when using thePatternflyReactobject.