Skip to content
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
83 changes: 55 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,19 @@ Other browser version may work too, but are not actively tested against.

Make sure, you have these requirements installed:

- Node.js ( https://nodejs.org/en/ )
- yarn ( https://yarnpkg.com/ )
- make
- git
- Node.js ( https://nodejs.org/ )
- make
- git

On OSX you need `gnu-tar` instead of tar (GNU tar supports the `--transform` option).
Please install it with e.g. `brew install gnu-tar`.
We use [pnpm](https://pnpm.io/) as package manager.
You don't need to install it globally - the Makefile runs it via `npx pnpm`.

## Development installation

The following commands will generate a `bundle.min.js` file in the `dist` directory
The following commands install all dependencies and build the bundle in the `dist` directory,
which contains Patterns and all its dependencies:

git clone git://github.com/Patternslib/Patterns.git
git clone https://github.com/Patternslib/Patterns.git
cd Patterns
make

Expand All @@ -47,6 +46,41 @@ To start the development server, use `make serve` or `npx yarn start` and access
The files are watched and the bundle re-built on changes.
You can access the bundle directly at [http://localhost:3001/bundle.min.js](http://localhost:3001/bundle.min.js).

## Makefile targets

The Makefile includes the shared Makefile from [@patternslib/dev](https://github.com/Patternslib/dev), which provides most of the targets.
On a fresh checkout, run `make install` first - after that, all the shared targets are available.

### User targets

| Target | Description |
| ------------------------------ | ---------------------------------------------------------------------------------------------------------------- |
| `make`, `make all` | Build the bundle and the CSS. |
| `make install` | Install the dependencies with pnpm and set up the commitlint `commit-msg` git hook. |
| `make update` | Update pnpm and the dependencies on a new `dependencies-update` branch, creating separate commits for each step. |
| `make clean-dist` | Remove the `dist/` directory. |
| `make clean` | Remove `dist/`, `node_modules/` and the bundle analysis files `stats.json` and `stats.html`. |
| `make lint`, `make eslint` | Lint the `src/` directory with ESLint. |
| `make format`, `make prettier` | Format all files with Prettier. |
| `make check`, `make test` | Run ESLint, then the Jest tests. |
| `make serve`, `make start` | Start the webpack development server on [http://localhost:3001/](http://localhost:3001/). |
| `make watch` | Build a development bundle and rebuild it on changes. |
| `make bundle` | Unlink any linked dependencies, reinstall and build the production bundle in `dist/`. |
| `make build` | Build the bundle and the CSS. |
| `make css` | Compile `_sass/_patterns.scss` to `style/patterns.css`. |
| `make depends-parser` | Regenerate the `pat-depends` expression parser from `src/lib/depends_parse.pegjs`. |
| `make release-major` | Release a new major version and update the [Patternslib.com](https://patternslib.com) website. |
| `make release-minor` | Release a new minor version and update the [Patternslib.com](https://patternslib.com) website. |
| `make release-patch` | Release a new patch version and update the [Patternslib.com](https://patternslib.com) website. |
| `make prerelease-alpha` | Release a new alpha pre-release. |
| `make prerelease-beta` | Release a new beta pre-release. |

To create GitHub releases, add a `GITHUB_TOKEN` to a `.env` file.
The Makefile reads `.env` automatically.
See [release-it GitHub releases](https://github.com/release-it/release-it/blob/master/docs/github-releases.md#automated) and [GitHub tokens](https://github.com/settings/tokens).

For more details, see the [@patternslib/dev README](https://github.com/Patternslib/dev).

## Layout

The individual patterns are located in their own folders in `./src/pat/`.
Expand All @@ -58,10 +92,8 @@ Each pattern folder contains some or all of the following files:
- A javascript file which implements the pattern's functionality.
- A Sass (.scss) file which provides the CSS associated with the pattern.

To generate CSS files from the pattern's included Sass files, type `make all_css`
and the css files will be generated in the same location as the Sass files.

You'll need to have a Sass compiler installed.
To compile the Sass files to `style/patterns.css`, run `make css`.
The Sass compiler is installed with the development dependencies.

## How to demo patterns

Expand Down Expand Up @@ -95,7 +127,7 @@ The simplest way to run the tests are to use make:

make check

This will install all required npm and bower packages and run the tests.
This will install all required packages, lint the code with ESLint and run the tests with Jest.

### Debugging tests

Expand Down Expand Up @@ -139,24 +171,19 @@ global settings or access otherwise hidden objects.
| window.\_\_patternslib_mf_initialized | Promise provided by the Module Federation helper of `@patternslib/dev`, resolved once all remote bundles are initialized. The registry waits for it before the initial scan. | undefined |
| window.\_\_patternslib_mf_init_timeout | Maximum time in milliseconds the registry waits for Module Federation remotes before scanning anyway. | 5000 |

### Bundle build analyzation

https://survivejs.com/webpack/optimizing/build-analysis/
https://formidable.com/blog/2018/finding-webpack-duplicates-with-inspectpack-plugin/

Build the stats.json file:

yarn build:stats

Check dependency tree and why which package was included:
https://www.npmjs.com/package/whybundled
### Bundle analysis

whybundled stats.json
These targets build the production bundle with webpack and analyze the resulting `stats.json`.
`stats.json` is rebuilt when `pnpm-lock.yaml` changes.
To force a rebuild, remove it or run `make clean`.

Visualize dependency tree and analyze bundle size:
https://www.npmjs.com/package/webpack-bundle-analyzer
| Target | Description |
| ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `make analyze-bundle-dependencies` | Show why each package was included in the bundle, using [whybundled](https://github.com/d4rkr00t/whybundled). |
| `make analyze-bundle-treemap` | Show the bundle as treemap, using [webpack-bundle-analyzer](https://github.com/webpack/webpack-bundle-analyzer). |
| `make analyze-bundle-sunburst` | Render the bundle as sunburst chart into `stats.html` and open it in the browser, using [webpack-visualizer](https://github.com/jonamat/webpack-visualizer). |

webpack-bundle-analyzer stats.json
To open `stats.html` with a specific browser, pass the `OPEN` variable, e.g. `make analyze-bundle-sunburst OPEN=firefox`.

### Organisations and projects which use Patternslib

Expand Down
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"title": "Markup patterns to drive behaviour.",
"description": "Patternslib is a JavaScript library that enables designers to build rich interactive prototypes without the need for writing any Javascript. All events are triggered by classes and other attributes in the HTML, without abusing the HTML as a programming language. Accessibility, SEO and well structured HTML are core values of Patterns.",
"license": "BSD-3-Clause",
"packageManager": "pnpm@12.21.0",
"packageManager": "pnpm@12.23.0",
"dependencies": {
"@fullcalendar/adaptive": "^5.11.3",
"@fullcalendar/core": "^5.11.3",
Expand Down Expand Up @@ -36,13 +36,13 @@
"tippy.js": "^6.3.7"
},
"devDependencies": {
"@patternslib/dev": "^4.4.0",
"@patternslib/dev": "^4.6.0",
"@patternslib/pat-content-mirror": "^4.0.2",
"@patternslib/pat-doclock": "^3.0.1",
"@patternslib/pat-shopping-cart": "^3.0.1",
"@patternslib/pat-doclock": "^4.0.0",
"@patternslib/pat-shopping-cart": "^4.0.0",
"@patternslib/pat-sortable-table": "^4.0.0",
"@patternslib/pat-tiptap": "^4.11.1",
"@patternslib/pat-upload": "^3.1.2",
"@patternslib/pat-upload": "^4.0.0",
"css.escape": "^1.5.1",
"pegjs": "0.11.0-master.b7b87ea"
},
Expand All @@ -53,7 +53,6 @@
"start": "BUILD_ENV=patternslib NODE_ENV=development webpack serve --config webpack/webpack.config.js",
"build": "BUILD_ENV=patternslib NODE_ENV=production webpack --config webpack/webpack.config.js",
"build:dev": "BUILD_ENV=patternslib NODE_ENV=development webpack --config webpack/webpack.config.js",
"build:stats": "BUILD_ENV=patternslib NODE_ENV=production webpack --config webpack/webpack.config.js --json > stats.json",
"test": "jest",
"testwatch": "jest --watch",
"watch": "BUILD_ENV=patternslib NODE_ENV=development webpack --config webpack/webpack.config.js --watch"
Expand Down
Loading