Skip to content

Commit 8535733

Browse files
committed
working locally
1 parent 30c4dde commit 8535733

File tree

6 files changed

+600
-6620
lines changed

6 files changed

+600
-6620
lines changed

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@
1212
},
1313
"eslint.alwaysShowStatus": true,
1414
"eslint.workingDirectories": ["src"],
15-
"typescript.tsdk": "node_modules/typescript/lib"
15+
"typescript.tsdk": "node_modules/typescript/lib",
16+
"[jsonc]": {
17+
"editor.defaultFormatter": "vscode.json-language-features"
18+
}
1619
}

package.json

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
{
22
"name": "nhsuk-react-components",
33
"version": "5.0.0",
4-
"files": ["dist", "lib"],
4+
"files": [
5+
"dist",
6+
"lib"
7+
],
58
"main": "dist/cjs/index.js",
69
"module": "dist/esm/index.js",
710
"types": "dist/index.d.ts",
@@ -31,31 +34,31 @@
3134
"react-dom": "^19.0.0"
3235
},
3336
"devDependencies": {
34-
"react": "^19.1.1",
35-
"react-dom": "^19.1.1",
36-
3737
"@babel/core": "^7.24.1",
3838
"@rollup/plugin-commonjs": "^25.0.7",
3939
"@rollup/plugin-node-resolve": "^15.2.3",
40+
"@rollup/plugin-terser": "^0.4.4",
4041
"@rollup/plugin-typescript": "^11.1.6",
41-
"rollup": "^4.13.0",
42-
"rollup-plugin-dts": "^6.1.0",
43-
"rollup-plugin-peer-deps-external": "^2.2.4",
44-
42+
"@storybook/addon-essentials": "^8.0.5",
4543
"@storybook/react": "^8.0.5",
4644
"@storybook/react-vite": "^8.0.5",
47-
"@storybook/addon-essentials": "^8.0.5",
4845
"@storybook/theming": "^8.0.5",
49-
5046
"@testing-library/react": "^16.3.0",
5147
"@types/react": "^18.2.60",
5248
"@types/react-dom": "^18.2.19",
53-
49+
"nhsuk-frontend": "^9.0.1",
50+
"react": "^19.1.1",
51+
"react-dom": "^19.1.1",
52+
"rollup": "^4.13.0",
53+
"rollup-plugin-dts": "^6.1.0",
54+
"rollup-plugin-peer-deps-external": "^2.2.4",
55+
"rollup-plugin-preserve-directives": "^0.4.0",
56+
"rollup-plugin-tsconfig-paths": "^1.5.2",
57+
"sass": "^1.53.0",
58+
"tslib": "^2.8.1",
5459
"typescript": "5.3.3",
5560
"vite": "^4.5.3",
56-
"vite-tsconfig-paths": "^4.3.2",
57-
"nhsuk-frontend": "^9.0.1",
58-
"sass": "^1.53.0"
61+
"vite-tsconfig-paths": "^4.3.2"
5962
},
6063
"license": "MIT",
6164
"packageManager": "[email protected]"

rollup.config.mjs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,76 +13,76 @@ import packageJson from './package.json' assert { type: 'json' };
1313
// suppresses warnings printed to console as part of bundling components with directives present.
1414
const onWarnSuppression = {
1515
onwarn(warning, warn) {
16-
if (warning.code === 'MODULE_LEVEL_DIRECTIVE' && warning.message.includes(`"use client"`)) {
17-
return;
18-
}
16+
if (warning.code === 'MODULE_LEVEL_DIRECTIVE' && warning.message.includes(`"use client"`)) return;
1917
warn(warning);
2018
},
2119
};
2220

23-
const commonPlugins = [external(), tsPaths(), resolve(), commonjs()];
21+
// Keep react 19 out of the bundle
22+
const externals = ['react', 'react-dom', 'react/jsx-runtime'];
23+
24+
const commonPlugins = [
25+
external(), // auto-externalize peer deps
26+
tsPaths(), // respect tsconfig paths in source
27+
resolve({ extensions: ['.mjs', '.js', '.ts', '.tsx'] }),
28+
commonjs(),
29+
];
2430

2531
export default [
26-
// cjs export
32+
// CJS (single file)
2733
{
2834
input: 'src/index.ts',
35+
external: externals,
2936
output: [
3037
{
31-
file: packageJson.main,
38+
file: packageJson.main, // e.g. dist/cjs/index.js
3239
format: 'cjs',
3340
sourcemap: true,
3441
},
3542
],
3643
plugins: [
3744
...commonPlugins,
3845
typescript({
39-
tsconfig: 'bundle-base.tsconfig.json',
40-
compilerOptions: {
41-
declaration: false,
42-
},
46+
// IMPORTANT: dedicated build tsconfig (noEmit, no jest/node types)
47+
tsconfig: './tsconfig.build.json',
4348
}),
44-
terser(),
49+
preserveDirectives(), // keep "use client" etc.
50+
terser({ compress: { directives: false } }),
4551
],
4652
...onWarnSuppression,
4753
},
48-
// esm export
54+
55+
// ESM (single file)
4956
{
5057
input: 'src/index.ts',
58+
external: externals,
5159
output: [
5260
{
53-
dir: packageJson.module,
61+
file: packageJson.module, // e.g. dist/esm/index.js
5462
format: 'esm',
5563
sourcemap: true,
56-
preserveModules: true,
57-
preserveModulesRoot: 'src',
5864
},
5965
],
6066
plugins: [
6167
...commonPlugins,
6268
typescript({
63-
tsconfig: 'bundle-base.tsconfig.json',
64-
compilerOptions: {
65-
declaration: true,
66-
declarationDir: 'dist/esm',
67-
emitDeclarationOnly: true,
68-
outDir: 'dist/esm',
69-
},
69+
tsconfig: './tsconfig.build.json',
7070
}),
7171
preserveDirectives(),
7272
terser({ compress: { directives: false } }),
7373
],
7474
...onWarnSuppression,
7575
},
76-
// type bundling
76+
77+
// Type definitions (bundled .d.ts)
7778
{
7879
input: 'src/index.ts',
80+
external: externals,
7981
output: [{ file: 'dist/index.d.ts', format: 'esm' }],
80-
external: [],
8182
plugins: [
8283
dts({
83-
compilerOptions: {
84-
paths: tsBuildConfig.compilerOptions.paths,
85-
},
84+
// carry over path mapping if you have any
85+
compilerOptions: { paths: tsBuildConfig?.compilerOptions?.paths ?? {} },
8686
}),
8787
],
8888
},

tsconfig.build.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"noEmit": true, // Rollup writes JS; TS only type-checks
5+
"declaration": false,
6+
"declarationMap": false,
7+
"types": [] // avoid pulling jest/node types into the build
8+
},
9+
"include": [
10+
"src/**/*"
11+
],
12+
"exclude": [
13+
"**/*.test.*",
14+
"**/*.spec.*",
15+
"**/*.stories.*",
16+
"stories",
17+
"tests",
18+
"jest.config.*"
19+
]
20+
}

tsconfig.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
"target": "es6",
55
"module": "esnext",
66
"moduleResolution": "node",
7-
"declaration": true,
87
"baseUrl": "./",
9-
"types": ["jest", "node"],
8+
"noEmit": true,
9+
"declaration": false,
10+
"declarationMap": false,
11+
"types": [],
1012
"sourceMap": true,
1113
"forceConsistentCasingInFileNames": true,
1214
"allowSyntheticDefaultImports": true,

0 commit comments

Comments
 (0)