Skip to content

Commit dba533b

Browse files
committed
updated rollup config
1 parent fae9b6e commit dba533b

File tree

1 file changed

+83
-78
lines changed

1 file changed

+83
-78
lines changed

rollup.config.mjs

Lines changed: 83 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -12,95 +12,100 @@ import tsBuildConfig from './bundle-base.tsconfig.json' assert { type: 'json' };
1212
import packageJson from './package.json' assert { type: 'json' };
1313

1414
const onWarnSuppression = {
15-
onwarn(warning, warn) {
16-
if (warning.code === 'MODULE_LEVEL_DIRECTIVE' && warning.message.includes(`"use client"`)) return;
17-
warn(warning);
18-
},
15+
onwarn(warning, warn) {
16+
if (warning.code === 'MODULE_LEVEL_DIRECTIVE' && warning.message.includes(`"use client"`)) return;
17+
warn(warning);
18+
},
1919
};
2020

2121
const commonPlugins = [
22-
external(),
23-
tsPaths(),
24-
resolve({ extensions: ['.mjs', '.js', '.ts', '.tsx'] }),
25-
commonjs(),
26-
// ⬇️ compile SCSS → CSS for any `import './file.scss'`
27-
postcss({
28-
extract: true, // or a filename like 'styles.css'
29-
modules: false,
30-
minimize: false,
31-
use: { sass: { quietDeps: true } }, // uses Dart Sass
32-
includePaths: ['node_modules'], // lets you @use "nhsuk-frontend/..." cleanly
33-
}),
22+
external(),
23+
tsPaths(),
24+
resolve({ extensions: ['.mjs', '.js', '.ts', '.tsx'] }),
25+
commonjs(),
26+
postcss({
27+
extract: true,
28+
modules: false,
29+
minimize: false,
30+
use: { sass: { quietDeps: true } },
31+
includePaths: ['node_modules'],
32+
}),
3433
];
3534

36-
// JS-only version of preserveDirectives
3735
const jsOnlyPreserveDirectives = preserveDirectives({
38-
include: ['**/*.{js,jsx,ts,tsx,mjs,cjs}'],
39-
exclude: ['**/*.{css,scss,sass,less,styl}'],
36+
include: ['**/*.{js,jsx,ts,tsx,mjs,cjs}'],
37+
exclude: ['**/*.{css,scss,sass,less,styl}'],
4038
});
4139

4240
export default [
43-
// cjs export
44-
{
45-
input: 'src/index.ts',
46-
output: [{ file: packageJson.main, format: 'cjs', sourcemap: true }],
47-
plugins: [
48-
...commonPlugins,
49-
typescript({
50-
tsconfig: 'bundle-base.tsconfig.json',
51-
compilerOptions: { declaration: false },
52-
}),
53-
terser(),
54-
],
55-
...onWarnSuppression,
56-
},
41+
// cjs export
42+
{
43+
input: 'src/index.ts',
44+
output: [{ file: packageJson.main, format: 'cjs', sourcemap: true }],
45+
plugins: [
46+
...commonPlugins,
47+
typescript({
48+
tsconfig: 'bundle-base.tsconfig.json',
49+
compilerOptions: { declaration: false },
50+
}),
51+
terser(),
52+
],
53+
...onWarnSuppression,
54+
},
5755

58-
// esm export
59-
{
60-
input: 'src/index.ts',
61-
output: [
62-
{
63-
dir: packageJson.module,
64-
format: 'esm',
65-
sourcemap: true,
66-
preserveModules: true,
67-
preserveModulesRoot: 'src',
68-
},
69-
],
70-
plugins: [
71-
...commonPlugins,
72-
typescript({
73-
tsconfig: 'bundle-base.tsconfig.json',
74-
compilerOptions: {
75-
declaration: false, // don’t emit .d.ts here
76-
emitDeclarationOnly: false,
77-
outDir: undefined, // let Rollup handle files
78-
},
79-
}),
80-
jsOnlyPreserveDirectives, // ⬅️ don't touch .scss
81-
terser({ compress: { directives: false } }),
82-
],
83-
...onWarnSuppression,
84-
},
56+
// esm export
57+
{
58+
input: 'src/index.ts',
59+
output: [
60+
{
61+
dir: packageJson.module,
62+
format: 'esm',
63+
sourcemap: true,
64+
preserveModules: true,
65+
preserveModulesRoot: 'src',
66+
},
67+
],
68+
plugins: [
69+
...commonPlugins,
70+
typescript({
71+
tsconfig: 'bundle-base.tsconfig.json',
72+
compilerOptions: {
73+
declaration: false,
74+
emitDeclarationOnly: false,
75+
outDir: undefined,
76+
},
77+
}),
78+
jsOnlyPreserveDirectives,
79+
terser({ compress: { directives: false } }),
80+
],
81+
...onWarnSuppression,
82+
},
8583

86-
// type bundling
87-
// type bundling
88-
{
89-
input: 'src/index.ts',
90-
output: [{ file: 'dist/index.d.ts', format: 'esm' }],
84+
// d.ts bundle ⬅️ only changes are here
85+
{
86+
input: 'src/index.ts',
87+
output: [{ file: 'dist/index.d.ts', format: 'es' }],
9188

92-
// ⬅️ Ignore any style imports during .d.ts bundling
93-
external: [/\.s?css$/i, /\.less$/i, /\.styl(us)?$/i],
94-
95-
plugins: [
96-
dts({
97-
respectExternal: true, // ⬅️ key: don't inline externals (like the styles we exclude)
98-
compilerOptions: {
99-
// carry over paths if you use them
100-
paths: tsBuildConfig.compilerOptions.paths,
101-
},
102-
}),
103-
],
104-
}
89+
// Keep styles and React types external so dts doesn't try to inline them
90+
external: [
91+
/\.s?css$/i,
92+
/\.less$/i,
93+
/\.styl(us)?$/i,
94+
/^react($|\/)/,
95+
/^react-dom($|\/)/,
96+
/^@types\/react($|\/)/,
97+
/^@types\/react-dom($|\/)/,
98+
],
10599

100+
plugins: [
101+
dts({
102+
respectExternal: true,
103+
// helps avoid lib type conflicts; also carry through your tsconfig paths
104+
compilerOptions: {
105+
skipLibCheck: true,
106+
paths: tsBuildConfig.compilerOptions?.paths ?? {},
107+
},
108+
}),
109+
],
110+
},
106111
];

0 commit comments

Comments
 (0)