This repository includes base files which are extended in Patternslib, Mockup or other projects.
It includes a Makefile which helps in installing, testing, building and releasing packages. The Makefile uses pnpm as package manager.
Include the shared Makefile from your project's Makefile and repeat the install target there.
On a fresh checkout, @patternslib/dev and its Makefile are not installed yet, so your project needs its own install target to bootstrap:
PNPM ?= npx pnpm
-include node_modules/@patternslib/dev/Makefile
.PHONY: install
pnpm-lock.yaml install:
$(PNPM) installThen run make install.
| Target | Description |
|---|---|
make install |
Install the dependencies with pnpm and set up the commitlint commit-msg git hook. |
make update |
Update pnpm and the project dependencies on a new dependencies-update branch. See Updating dependencies. |
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 test script from package.json. |
make serve, make start |
Run the start script from package.json, e.g. a webpack dev server. |
make watch |
Run the watch script from package.json. |
make bundle, make build |
Clean dist/ and run the build script from package.json, if there is one. Runs the bundle-pre target first. |
make release-major |
Release a new major version. |
make release-minor |
Release a new minor version. |
make release-patch |
Release a new patch version. |
make prerelease-alpha |
Release a new alpha pre-release. |
make prerelease-beta |
Release a new beta pre-release. |
The test, start, watch and build scripts are not provided by @patternslib/dev.
Define them in your project's package.json.
The release targets clean and reinstall the project, run make check and then use release-it to bump the version, generate the changelog, tag, publish to npm and create a GitHub release.
- To create GitHub releases, add a
GITHUB_TOKENto a.envfile in your project. The Makefile reads.envautomatically. See release-it GitHub releases and GitHub tokens. - If your project has a
buildscript, the bundle is built after the version bump and attached to the GitHub release asBUNDLENAME-bundle-VERSION.zip. Includedist/in thefileslist of yourpackage.json, so that the bundle is also published to npm.
To run tasks before the bundle is built, extend the bundle-pre target in your Makefile.
Use double colons, so that the base bundle-pre target is also run:
bundle-pre::
-pnpm unlink --recursive
pnpm installThese targets build the bundle with webpack and analyze the resulting stats.json.
They need a build script in your project's package.json.
| Target | Description |
|---|---|
make analyze-bundle-dependencies |
Show why each package was included in the bundle, using whybundled. |
make analyze-bundle-treemap |
Show the bundle as treemap, using 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. |
stats.json is rebuilt when pnpm-lock.yaml changes.
To rebuild it after source changes, run make clean or delete stats.json.
Override these variables in your Makefile or on the command line, e.g. make analyze-bundle-sunburst OPEN=firefox.
| Variable | Default | Description |
|---|---|---|
PNPM |
npx pnpm |
Command to run pnpm. |
ESLINT |
npx eslint |
Command to run ESLint. |
PRETTIER |
npx prettier |
Command to run Prettier. |
WEBPACK_CONFIG |
webpack/webpack.config.js, if it exists (*) |
Webpack config used by the bundle analysis targets. |
OPEN |
xdg-open, open on macOS |
Command to open stats.html in the browser. |
(*) Otherwise no --config is passed and webpack-cli finds the config itself, e.g. webpack.config.js in the project root.
Run make update to update the dependencies in this or your dependent project.
It creates a dependencies-update branch and makes up to three separate commits: one for the pnpm update, one for the updated dependencies in package.json, and one for pnpm-lock.yaml.
The dependencies are updated interactively with pnpm update --latest --interactive.
package.json must not have uncommitted changes.
Finally, make update runs make upgrade to apply the upgrade steps of a possibly updated @patternslib/dev.
make update runs the upgrade steps automatically.
If you updated @patternslib/dev in another way, run make upgrade in your project.
Each upgrade step creates its own commit. Current upgrades:
- Remove the
.huskydirectory in favor of git hooks. - Create
eslint.config.jsand remove the old.eslintrc.js. - Remove the
build:statsscript frompackage.json, replaced bymake stats.json. - Add
stats.jsonandstats.htmlto.gitignore.
The last two steps skip files with uncommitted changes and run again on the next upgrade.
@patternslib/dev switched from Yarn to pnpm in version 4.3.0.
The shared Makefile uses pnpm for installation and for running the build, test and start scripts.
Projects which still use Yarn should migrate:
-
Pin the pnpm version you intend to use in your project's
package.json:"packageManager": "pnpm@12.3.4",
-
Add a
pnpm-workspace.yamlfile at the project's workspace root:# No nested node_modules for Module Federation. shamefullyHoist: true
You might also want to include the following to allow to build "@patternslib/dev" and to include releases of "@patternslib/dev" which are younger than the "minimumReleaseAge":
allowBuilds: "@patternslib/dev": true minimumReleaseAgeExclude: - "@patternslib/dev"
For more information, see the pnpm configuration reference.
-
Change the
yarnreferences in your Makefile to usepnpm, as shown in Using the Makefile in your project.If you use
yarn linkoryarn unlinkin your Makefile, update it to fit the new pnpm syntax. -
You might need to include pnpm in the
transformIgnorePatternsfield of your Jest configuration to make the tests pass. See this project'sjest.config.jsfor an example. -
Update the CI configuration to use pnpm and its cache - see this project's
.github/workflows/test.yml. -
Run
make install, addpnpm-lock.yamlto the git repository and removeyarn.lock.
The release process based on release-it includes automatic changelog generation via conventional-commit, commitlint and a git pre-commit hook. Please check the code style guide for the commit specification!