Skip to content

Commit 7ed748a

Browse files
Preserve build output (non-minified) for all modules
1 parent 80289fb commit 7ed748a

File tree

9 files changed

+309
-429
lines changed

9 files changed

+309
-429
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import React, { PureComponent } from 'react';
2727
import { Button } from 'nhsuk-react-components';
2828

2929
// Or you can import components directly
30-
import Button from 'nhsuk-react-components/lib/components/button';
30+
import Button from 'nhsuk-react-components/dist/esm/components/button';
3131

3232
class GetStartedButton extends PureComponent {
3333
render() {

bundle-base.tsconfig.json

Lines changed: 0 additions & 31 deletions
This file was deleted.

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { pathsToModuleNameMapper } = require('ts-jest');
2-
const { compilerOptions } = require('./tsconfig.json');
2+
const { compilerOptions } = require('./tsconfig.base.json');
33

44
const jestConfig = {
55
testEnvironment: 'jsdom',

package.json

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,26 @@
55
"name": "NHS England"
66
},
77
"files": [
8-
"dist",
9-
"lib"
8+
"dist"
109
],
10+
"sideEffects": false,
11+
"exports": {
12+
".": {
13+
"import": {
14+
"types": "./dist/esm/index.d.ts",
15+
"default": "./dist/esm/index.js"
16+
},
17+
"require": {
18+
"types": "./dist/cjs/index.d.ts",
19+
"default": "./dist/cjs/index.js"
20+
}
21+
},
22+
"./*": "./*",
23+
"./package.json": "./package.json"
24+
},
1125
"main": "dist/cjs/index.js",
12-
"module": "dist/esm",
13-
"types": "dist/index.d.ts",
26+
"module": "dist/esm/index.js",
27+
"types": "dist/esm/index.d.ts",
1428
"scripts": {
1529
"cleanup": "rm -rf dist/ > /dev/null && rm -rf lib/ > /dev/null",
1630
"storybook": "storybook dev -p 6006",
@@ -28,10 +42,9 @@
2842
"devDependencies": {
2943
"@babel/core": "^7.24.1",
3044
"@babel/plugin-transform-modules-commonjs": "^7.23.3",
31-
"@rollup/plugin-commonjs": "^25.0.7",
32-
"@rollup/plugin-node-resolve": "^15.2.3",
33-
"@rollup/plugin-terser": "^0.4.4",
34-
"@rollup/plugin-typescript": "^11.1.6",
45+
"@rollup/plugin-commonjs": "^28.0.6",
46+
"@rollup/plugin-node-resolve": "^16.0.1",
47+
"@rollup/plugin-typescript": "^12.1.4",
3548
"@storybook/addon-actions": "^8.0.5",
3649
"@storybook/addon-essentials": "^8.0.5",
3750
"@storybook/addon-links": "^8.0.5",
@@ -49,7 +62,6 @@
4962
"@types/node": "^15.0.2",
5063
"@types/react": "^18.2.60",
5164
"@types/react-dom": "^18.2.19",
52-
"@types/rollup-plugin-peer-deps-external": "^2.2.1",
5365
"@typescript-eslint/eslint-plugin": "^7.1.0",
5466
"@typescript-eslint/parser": "^7.1.0",
5567
"babel-jest": "^29.7.0",
@@ -72,11 +84,7 @@
7284
"react": "^18.2.0",
7385
"react-dom": "^18.2.0",
7486
"regenerator-runtime": "^0.13.7",
75-
"rollup": "^4.13.0",
76-
"rollup-plugin-dts": "^6.1.0",
77-
"rollup-plugin-peer-deps-external": "^2.2.4",
78-
"rollup-plugin-preserve-directives": "^0.4.0",
79-
"rollup-plugin-tsconfig-paths": "^1.5.2",
87+
"rollup": "^4.52.4",
8088
"sass": "^1.53.0",
8189
"storybook": "^8.0.5",
8290
"ts-jest": "^29.1.2",

rollup.config.mjs

Lines changed: 41 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,47 @@
1-
import resolve from '@rollup/plugin-node-resolve';
1+
import { join } from 'node:path';
22
import commonjs from '@rollup/plugin-commonjs';
3+
import { nodeResolve } from '@rollup/plugin-node-resolve';
34
import typescript from '@rollup/plugin-typescript';
4-
import terser from '@rollup/plugin-terser';
5-
import external from 'rollup-plugin-peer-deps-external';
6-
import { dts } from 'rollup-plugin-dts';
7-
import tsPaths from 'rollup-plugin-tsconfig-paths';
8-
import preserveDirectives from 'rollup-plugin-preserve-directives';
9-
10-
import tsBuildConfig from './bundle-base.tsconfig.json' with { type: 'json' };
5+
import { defineConfig } from 'rollup';
116
import packageJson from './package.json' with { type: 'json' };
7+
import tsBuildConfig from './tsconfig.build.json' with { type: 'json' };
128

13-
const commonPlugins = [external(), tsPaths(), resolve(), commonjs()];
9+
const { outDir } = tsBuildConfig.compilerOptions;
1410

15-
export default [
16-
// cjs export
17-
{
18-
input: 'src/index.ts',
19-
output: [
20-
{
21-
file: packageJson.main,
22-
format: 'cjs',
23-
sourcemap: true,
24-
},
25-
],
26-
plugins: [
27-
...commonPlugins,
28-
typescript({
29-
tsconfig: 'bundle-base.tsconfig.json',
30-
compilerOptions: {
31-
declaration: false,
32-
},
33-
}),
34-
terser(),
35-
],
36-
...onWarnSuppression,
37-
},
38-
// esm export
39-
{
40-
input: 'src/index.ts',
41-
output: [
42-
{
43-
dir: packageJson.module,
44-
format: 'esm',
45-
sourcemap: true,
46-
preserveModules: true,
47-
preserveModulesRoot: 'src',
48-
},
49-
],
50-
plugins: [
51-
...commonPlugins,
52-
typescript({
53-
tsconfig: 'bundle-base.tsconfig.json',
54-
compilerOptions: {
55-
declaration: true,
56-
declarationDir: 'dist/esm',
57-
emitDeclarationOnly: true,
58-
outDir: 'dist/esm',
11+
export default defineConfig(
12+
/** @type {const} */ (['cjs', 'esm']).map(
13+
/**
14+
* Rollup options for each module format
15+
*
16+
* @param {ModuleFormat} format
17+
* @returns {RollupOptions}
18+
*/
19+
(format) => ({
20+
input: 'src/index.ts',
21+
external: Object.keys(packageJson.peerDependencies),
22+
output: [
23+
{
24+
dir: join(outDir, format),
25+
format,
26+
preserveModules: true,
27+
preserveModulesRoot: 'src',
28+
sourcemap: true,
5929
},
60-
}),
61-
preserveDirectives(),
62-
terser({ compress: { directives: false } }),
63-
],
64-
...onWarnSuppression,
65-
},
66-
// type bundling
67-
{
68-
input: 'src/index.ts',
69-
output: [{ file: 'dist/index.d.ts', format: 'esm' }],
70-
external: [],
71-
plugins: [
72-
dts({
73-
compilerOptions: {
74-
paths: tsBuildConfig.compilerOptions.paths,
75-
},
76-
}),
77-
],
78-
},
79-
];
30+
],
31+
plugins: [
32+
nodeResolve(),
33+
commonjs(),
34+
typescript({
35+
tsconfig: 'tsconfig.build.json',
36+
compilerOptions: {
37+
outDir: join(outDir, format),
38+
},
39+
}),
40+
],
41+
}),
42+
),
43+
);
44+
45+
/**
46+
* @import { ModuleFormat, RollupOptions } from 'rollup'
47+
*/

tsconfig.base.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"compilerOptions": {
3+
"allowJs": true,
4+
"checkJs": true,
5+
"esModuleInterop": true,
6+
"module": "ESNext",
7+
"moduleResolution": "Bundler",
8+
"noEmit": true,
9+
"resolveJsonModule": true,
10+
"skipLibCheck": true,
11+
"strict": false,
12+
"strictBindCallApply": true,
13+
"strictFunctionTypes": true,
14+
"strictNullChecks": true,
15+
"target": "ESNext",
16+
"types": [],
17+
"paths": {
18+
"@components/*": ["./src/components/*"],
19+
"@content-presentation/*": ["./src/components/content-presentation/*"],
20+
"@form-elements/*": ["./src/components/form-elements/*"],
21+
"@navigation/*": ["./src/components/navigation/*"],
22+
"@typography/*": ["./src/components/typography/*"],
23+
"@util/*": ["./src/util/*"],
24+
"@patterns/*": ["./src/patterns/*"]
25+
}
26+
},
27+
"exclude": ["./dist", "./node_modules"]
28+
}

tsconfig.build.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"extends": "./tsconfig.base.json",
3+
"compilerOptions": {
4+
"declaration": true,
5+
"declarationMap": true,
6+
"emitDeclarationOnly": true,
7+
"jsx": "react",
8+
"lib": ["ESNext", "DOM"],
9+
"outDir": "./dist",
10+
"rootDir": "./src",
11+
"strict": true,
12+
"sourceMap": true,
13+
"target": "ES2015",
14+
"types": ["node"]
15+
},
16+
"include": ["./src"],
17+
"exclude": ["**/__mocks__", "**/__tests__", "./src/setupTests.ts"]
18+
}

tsconfig.json

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,17 @@
11
{
2+
"extends": "./tsconfig.base.json",
23
"compilerOptions": {
34
"jsx": "react",
4-
"target": "es6",
5-
"module": "esnext",
6-
"moduleResolution": "node",
7-
"declaration": true,
8-
"baseUrl": "./",
9-
"types": ["jest", "node"],
10-
"sourceMap": true,
11-
"forceConsistentCasingInFileNames": true,
12-
"allowSyntheticDefaultImports": true,
13-
"esModuleInterop": true,
14-
"skipLibCheck": true,
15-
"strict": true,
16-
"strictNullChecks": true,
17-
"resolveJsonModule": true,
18-
"allowJs": true,
19-
"outDir": "./dist",
20-
"paths": {
21-
"@components/*": ["src/components/*"],
22-
"@content-presentation/*": ["src/components/content-presentation/*"],
23-
"@form-elements/*": ["src/components/form-elements/*"],
24-
"@navigation/*": ["src/components/navigation/*"],
25-
"@typography/*": ["src/components/typography/*"],
26-
"@util/*": ["src/util/*"],
27-
"@patterns/*": ["src/patterns/*"]
28-
}
5+
"lib": ["ESNext", "DOM"],
6+
"target": "ES2015",
7+
"types": ["jest", "node"]
298
},
30-
"include": ["src", "stories"],
31-
"exclude": ["node_modules", "build"]
9+
"include": [
10+
"./.storybook/*.ts",
11+
"./src/**/*.ts",
12+
"./src/**/*.tsx",
13+
"./stories/**/*.tsx",
14+
"./*.config.js",
15+
"./*.config.mjs"
16+
]
3217
}

0 commit comments

Comments
 (0)