Skip to content

Commit 45685af

Browse files
Add local development guidance and improvements (#376)
* Only use `NODE_ENV=production` for production builds * Log warnings without throwing errors during development * Separate build and clean scripts for Windows * Upgrade Yarn using `yarn set version stable` * Update documentation to include running locally
1 parent eb91992 commit 45685af

9 files changed

Lines changed: 244 additions & 17 deletions

File tree

‎.github/dependabot.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ updates:
5353
tools:
5454
patterns:
5555
- '@storybook/*'
56+
- 'del-cli'
5657
- 'outdent'
5758
- 'sass-embedded'
5859
- 'storybook'

‎.github/workflows/ci.yml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,15 @@ jobs:
4141
- name: Jest Tests
4242
run: yarn test --coverage
4343

44-
- name: Typescript build
44+
- name: Package build
4545
run: yarn build
46+
env:
47+
NODE_ENV: production
4648

4749
- name: Storybook build
4850
run: yarn build-storybook
51+
env:
52+
NODE_ENV: production
4953

5054
- name: Switch to PR branch
5155
if: ${{ github.event_name == 'pull_request' && env.CHROMATIC_PROJECT_TOKEN }}

‎.github/workflows/release.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ jobs:
3636
- name: Jest Tests
3737
run: yarn test --coverage
3838

39-
- name: Typescript build
39+
- name: Package build
4040
run: yarn build
41+
env:
42+
NODE_ENV: production
4143

4244
- name: Publish npm package
4345
if: ${{ !github.event.release.prerelease }}

‎README.md‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ This repository contains the code for NHS.UK React components - a port of the [N
88

99
[View documentation and examples](https://nhsdigital.github.io/nhsuk-react-components)
1010

11-
## Installation
11+
## Install package
1212

13-
You can install this package using either `npm` or `yarn`.
13+
You can install this package into your service using either `npm` or `yarn`.
1414

1515
```bash
1616
npm install --save nhsuk-react-components
@@ -41,6 +41,30 @@ import { DateInput, Form } from 'nhsuk-react-components';
4141
</Form>;
4242
```
4343

44+
## Development
45+
46+
To run this project locally, set up Yarn using [Node.js corepack](https://github.com/nodejs/corepack#readme)
47+
48+
```bash
49+
npm install -g corepack
50+
corepack enable
51+
yarn install
52+
```
53+
54+
Then run the following:
55+
56+
1. **Build and watch package**
57+
58+
```bash
59+
yarn build --watch
60+
```
61+
62+
2. **Open documentation and examples**
63+
64+
```bash
65+
yarn storybook
66+
```
67+
4468
## Upgrading
4569

4670
- [Upgrading to 1.0](/docs/upgrade-to-1.0.md)

‎babel.config.cjs‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// Node.js environment with default
2-
// https://nodejs.org/en/learn/getting-started/nodejs-the-difference-between-development-and-production
3-
const { NODE_ENV = 'development' } = process.env;
1+
const { NODE_ENV } = process.env;
42

53
/**
64
* Babel config
@@ -27,7 +25,7 @@ module.exports = {
2725
[
2826
'@babel/preset-react',
2927
{
30-
development: NODE_ENV === 'test' || NODE_ENV === 'development',
28+
development: NODE_ENV !== 'production',
3129
runtime: 'automatic',
3230
useBuiltIns: true,
3331
},

‎package.json‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848
"!**/*.test.*"
4949
],
5050
"scripts": {
51-
"cleanup": "rm -rf dist/ > /dev/null",
52-
"build": "NODE_ENV=production yarn cleanup && rollup -c",
51+
"clean": "del-cli dist/*",
52+
"build": "rollup --config",
5353
"storybook": "storybook dev -p 6006",
5454
"build-storybook": "storybook build",
5555
"test": "jest --color",
@@ -92,6 +92,7 @@
9292
"babel-plugin-module-resolver": "^5.0.3",
9393
"babel-plugin-replace-import-extension": "^1.1.5",
9494
"classnames": "^2.5.1",
95+
"del-cli": "^7.0.0",
9596
"eslint": "^9.39.4",
9697
"eslint-config-prettier": "^10.1.8",
9798
"eslint-import-resolver-typescript": "^4.4.4",
@@ -125,7 +126,7 @@
125126
"react-dom": ">=18.2.0",
126127
"tslib": ">=2.8.0"
127128
},
128-
"packageManager": "yarn@4.10.3",
129+
"packageManager": "yarn@4.14.1",
129130
"publishConfig": {
130131
"access": "public"
131132
}

‎rollup.config.js‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import preserveDirectives from 'rollup-preserve-directives';
1111
import packageJson from './package.json' with { type: 'json' };
1212
import tsBuildConfig from './tsconfig.build.json' with { type: 'json' };
1313

14+
const { NODE_ENV } = process.env;
15+
1416
const { outDir } = tsBuildConfig.compilerOptions;
1517
const external = Object.keys(packageJson.peerDependencies);
1618

@@ -73,7 +75,13 @@ export default defineConfig(
7375

7476
// Handle warnings as errors
7577
onwarn(warning) {
76-
throw new Error(warning.message, { cause: warning });
78+
if (NODE_ENV === 'production') {
79+
throw new Error(warning.message, {
80+
cause: warning,
81+
});
82+
}
83+
84+
console.warn(warning.message);
7785
},
7886
}),
7987
),

‎stories/Welcome.mdx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ NHS.UK Frontend ported to React
99
[![CD Build and Publish to NPM](https://github.com/NHSDigital/nhsuk-react-components/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/NHSDigital/nhsuk-react-components/actions/workflows/release.yml)
1010
[![Bundle Size](https://img.shields.io/bundlephobia/minzip/nhsuk-react-components.svg)](https://bundlephobia.com/result?p=nhsuk-react-components)
1111

12-
## Installation
12+
## Install package
1313

14-
You can install this package using either `yarn` or `npm`.
14+
You can install this package into your service using either `npm` or `yarn`.
1515

1616
```bash
1717
npm install --save nhsuk-react-components
18+
1819
# Or
1920
yarn add nhsuk-react-components
2021
```

0 commit comments

Comments
 (0)