|
| 1 | +--- |
| 2 | +layout: layout-with-subnav.njk |
| 3 | +title: Installation |
| 4 | +heading: Developers |
| 5 | +tags: |
| 6 | + - developers |
| 7 | +permalink: /get-started/developers/installation/index.html |
| 8 | +subNavCollection: sortedDevelopers |
| 9 | +order: 10 |
| 10 | +bodyClasses: element-docs |
| 11 | +--- |
| 12 | + |
| 13 | +## How to install |
| 14 | + |
| 15 | +There are three ways you can install the Red Hat Design System's web components: CDN, NPM, or JSPM. Each element's "Code" page includes the same installation information with code snippets that are specific to that element. |
| 16 | + |
| 17 | +### Red Hat CDN |
| 18 | + |
| 19 | +{% alert title="CDN Prerelease", |
| 20 | + state="warning" %} |
| 21 | +<p>We are currently working on our CDN, which will be soon moving into beta. This will be the preferred method of installation in the near future. If you are a Red Hat associate and have questions or comments about the CDN or installation process please connect with us on Slack.</p> |
| 22 | +{% endalert %} |
| 23 | + |
| 24 | +The recommended way to load RHDS is via the Red Hat Digital Experience CDN, and using an [import map](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap). |
| 25 | + |
| 26 | +If you have full control over the page you are using, add an import map to the `<head>`, pointing to the CDN, or update any existing import map. If you are not responsible for the page's `<head>`, request that the page owner makes the change on your behalf. |
| 27 | + |
| 28 | +<rh-code-block> |
| 29 | + <script type="text/sample-javascript"> |
| 30 | + <script type="importmap"> |
| 31 | + { |
| 32 | + "imports": { |
| 33 | + "@rhds/elements/": "https://www.redhatstatic.com/dx/v1-alpha/@rhds/elements@1.1.0/elements/", |
| 34 | + "@patternfly/elements/": "https://www.redhatstatic.com/dx/v1-alpha/@patternfly/elements@2.2.2/" |
| 35 | + } |
| 36 | + } |
| 37 | + <</script><script type="text/sample-javascript">/script> |
| 38 | + </script> |
| 39 | +</rh-code-block> |
| 40 | + |
| 41 | +Once the import map is established, you can load the element with the following module, containing a [bare module specifier](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules). The example below shows how you'd load in <`rh-button>`. |
| 42 | + |
| 43 | +<rh-code-block> |
| 44 | + <script type="text/sample-javascript"> |
| 45 | + <script type="module"> |
| 46 | + import '@rhds/elements/rh-button/rh-button.js'; |
| 47 | + <</script><script type="text/sample-javascript">/script> |
| 48 | + </script> |
| 49 | +</rh-code-block> |
| 50 | + |
| 51 | +Note that modules may be placed in the `<head>`. Since they are deferred by default, they will not block rendering. |
| 52 | + |
| 53 | +### NPM |
| 54 | + |
| 55 | +Install RHDS using your team's preferred NPM package manager. |
| 56 | + |
| 57 | +<rh-code-block> |
| 58 | + <script type="text/sample-javascript"> |
| 59 | + npm install @rhds/elements |
| 60 | + </script> |
| 61 | +</rh-code-block> |
| 62 | + |
| 63 | +Once that's been accomplished, you will need to use a bundler to resolve the bare module specifiers and optionally optimize the package for your site's particular use case and needs. Comprehensive guides to bundling are beyond the scope of this page; read more about bundlers on their websites: |
| 64 | + |
| 65 | +- [Rollup](https://rollupjs.org/) |
| 66 | +- [esbuild](https://esbuild.github.io/) |
| 67 | +- [Parcel](https://parceljs.org/) |
| 68 | +- [Webpack](https://webpack.js.org/) |
| 69 | + |
| 70 | +### JSPM |
| 71 | + |
| 72 | +{% alert title="Public CDNs", |
| 73 | + state="warning" %} |
| 74 | +<p>JSPM and other public CDNs should not be used on corporate domains. Use them for <strong>development purposes only</strong>!</p> |
| 75 | +{% endalert %} |
| 76 | + |
| 77 | +Add an [import map](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap) to the `<head>`, pointing to the CDN, or update any existing import map. |
| 78 | + |
| 79 | +<rh-code-block> |
| 80 | + <script type="text/sample-javascript"> |
| 81 | + <script type="importmap"> |
| 82 | + { |
| 83 | + "imports": { |
| 84 | + "@rhds/elements/": "https://jspm.dev/@rhds/elements/", |
| 85 | + "@patternfly/elements/": "https://jspm.dev/@patternfly/elements/" |
| 86 | + } |
| 87 | + } |
| 88 | + <</script><script type="text/sample-javascript">/script> |
| 89 | + </script> |
| 90 | +</rh-code-block> |
| 91 | + |
| 92 | +Once the import map is established, you can load the element with the following module, containing a [bare module specifier](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules). The example below shows how you'd load in <`rh-button>`. |
| 93 | + |
| 94 | +<rh-code-block> |
| 95 | + <script type="text/sample-javascript"> |
| 96 | + <script type="module"> |
| 97 | + import '@rhds/elements/rh-button/rh-button.js'; |
| 98 | + <</script><script type="text/sample-javascript">/script> |
| 99 | + </script> |
| 100 | +</rh-code-block> |
| 101 | + |
| 102 | +Note that Modules may be placed in the `<head>`. Since they are deferred by default, they will not block rendering. |
| 103 | + |
| 104 | +{% feedback %} |
| 105 | + <h2>Designers</h2> |
| 106 | + <p>To get started using our design system as a designer, go to the <a href="get-started/designers">Designers</a> page.</p> |
| 107 | +{% endfeedback %} |
0 commit comments