Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/csev/tsugi-react-base

My patternfly seed playground
https://github.com/csev/tsugi-react-base

Last synced: 18 days ago
JSON representation

My patternfly seed playground

Awesome Lists containing this project

README

        

Tsugi React Base Tool
=====================

## Quick-start

```bash
# Get into your Tsugi mod folder
cd ... /mod
git clone https://github.com/csev/tsugi-react-base
cd tsugi-react-base
npm install && npm run start:dev
```
## Development scripts
```sh
# Install development/build dependencies
npm install

# Start the development server
npm run start:dev

# Before you run the `tsugi` build process, you must edit the `webpack.prod.js`
# file and edit the `publicPath` and `replace` field to reflect
# the actual path on your web server where the folder will be available
# TODO: Automate this :)

# Run a tsugi build (outputs to "dist" dir)
npm run build
```

## Other Scripts

```sh
# Run the test suite
npm run test

# Run the test suite with coverage
npm run test:coverage

# Run the linter
npm run lint

# Run the code formatter
npm run format

# Launch a tool to inspect the bundle size
npm run bundle-profile:analyze

# Start the express server (run a production build first)
npm run start

# Start storybook component explorer
npm run storybook

# Build storybook component explorer as standalone app (outputs to "storybook-static" dir)
npm run build:storybook
```

## Configurations
* [TypeScript Config](./tsconfig.json)
* [Webpack Config](./webpack.common.js)
* [Jest Config](./jest.config.js)
* [Editor Config](./.editorconfig)

## Raster image support

To use an image asset that's shipped with PatternFly core, you'll prefix the paths with "@assets". `@assets` is an alias for the PatternFly assets directory in node_modules.

For example:
```js
import imgSrc from '@assets/images/g_sizing.png';
Some image
```

You can use a similar technique to import assets from your local app, just prefix the paths with "@app". `@app` is an alias for the main src/app directory.

```js
import loader from '@app/assets/images/loader.gif';
Content loading />
<br />```</p>

<p>## Vector image support
<br />Inlining SVG in the app's markup is also possible.</p>

<p>```js
<br />import logo from '@app/assets/images/logo.svg';
<br /><span dangerouslySetInnerHTML={{__html: logo}} />
<br />```</p>

<p>You can also use SVG when applying background images with CSS. To do this, your SVG's must live under a `bgimages` directory (this directory name is configurable in [webpack.common.js](./webpack.common.js#L5)). This is necessary because you may need to use SVG's in several other context (inline images, fonts, icons, etc.) and so we need to be able to differentiate between these usages so the appropriate loader is invoked.
<br />```css
<br />body {
<br />  background: url(./assets/bgimages/img_avatar.svg);
<br />}
<br />```</p>

<p>## Adding custom CSS
<br />When importing CSS from a third-party package for the first time, you may encounter the error `Module parse failed: Unexpected token... You may need an appropriate loader to handle this file typ...`. You need to register the path to the stylesheet directory in [stylePaths.js](./stylePaths.js). We specify these explicity for performance reasons to avoid webpack needing to crawl through the entire node_modules directory when parsing CSS modules.</p>

<p>## Code quality tools
<br />* For accessibility compliance, we use [react-axe](https://github.com/dequelabs/react-axe)
<br />* To keep our bundle size in check, we use [webpack-bundle-analyzer](https://github.com/webpack-contrib/webpack-bundle-analyzer)
<br />* To keep our code formatting in check, we use [prettier](https://github.com/prettier/prettier)
<br />* To keep our code logic and test coverage in check, we use [jest](https://github.com/facebook/jest)
<br />* To ensure code styles remain consistent, we use [eslint](https://eslint.org/)
<br />* To provide a place to showcase custom components, we integrate with [storybook](https://storybook.js.org/)</p>

<p>## Multi environment configuration
<br />This project uses [dotenv-webpack](https://www.npmjs.com/package/dotenv-webpack) for exposing environment variables to your code. Either export them at the system level like `export MY_ENV_VAR=http://dev.myendpoint.com && npm run start:dev` or simply drop a `.env` file in the root that contains your key-value pairs like below:</p>

<p>```sh
<br />ENV_1=http://1.myendpoint.com
<br />ENV_2=http://2.myendpoint.com
<br />```</p>

<p>With that in place, you can use the values in your code like `console.log(process.env.ENV_1);`</p>

<p>