Skip to content

Commit 4f604da

Browse files
authored
Bundle use-local-storage-state package with @guardian/react-crossword (#2040)
* Extend Rollup config to allow bundling of external module
1 parent 07092ac commit 4f604da

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

.changeset/warm-bears-sink.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@guardian/react-crossword': minor
3+
---
4+
5+
Bundles `use-local-storage-state` package to enable consumers of the crossword package to transpile if required in order to support older browsers

configs/rollup/rollup.config.js

+19-7
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,52 @@ const output = {
1919
preserveModulesRoot: 'src',
2020
};
2121

22-
/** @type {Plugins} */
23-
const defaultPlugins = [
22+
/**
23+
* @param {import('rollup-plugin-node-externals').ExternalsOptions} externalsOptions
24+
* @returns {Plugins}
25+
*/
26+
27+
const defaultPlugins = (externalsOptions) => [
2428
nodeResolve({
2529
extensions: ['.cjs', '.mjs', '.js', '.jsx', '.ts', '.tsx', '.json'],
2630
}),
2731
commonjs(),
2832
json(),
29-
nodeExternals(),
33+
nodeExternals(externalsOptions),
3034
];
3135

3236
/**
3337
* @param {object} param0
3438
* @param {Plugins} [param0.plugins]
3539
* @param {Input} [param0.input]
40+
* @param {import('rollup-plugin-node-externals').ExternalsOptions} [param0.externalsOptions]
41+
* @param {import("rollup").RollupOptions["output"]} [param0.cjsOutputOptions]
3642
* @returns {import("rollup").RollupOptions[]}
3743
*/
38-
export default ({ input = defaultInput, plugins = [] } = {}) => [
44+
export default ({
45+
input = defaultInput,
46+
plugins = [],
47+
externalsOptions,
48+
cjsOutputOptions,
49+
} = {}) => [
3950
{
4051
input,
4152
output,
42-
plugins: [...defaultPlugins, ...plugins, esbuild()],
53+
plugins: [...defaultPlugins(externalsOptions), ...plugins, esbuild()],
4354
},
4455
{
4556
input,
4657
output: {
4758
...output,
59+
...cjsOutputOptions,
4860
format: 'cjs',
4961
entryFileNames: '[name].cjs',
5062
},
51-
plugins: [...defaultPlugins, ...plugins, esbuild()],
63+
plugins: [...defaultPlugins(externalsOptions), ...plugins, esbuild()],
5264
},
5365
{
5466
input,
5567
output,
56-
plugins: [...defaultPlugins, ...plugins, dts()],
68+
plugins: [...defaultPlugins(externalsOptions), ...plugins, dts()],
5769
},
5870
];

libs/@guardian/react-crossword/rollup.config.js

+2
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ import config from '../../../configs/rollup/rollup.config.js';
22

33
export default config({
44
input: 'src/index.ts',
5+
externalsOptions: { exclude: 'use-local-storage-state' },
6+
cjsOutputOptions: { exports: 'named' },
57
});

0 commit comments

Comments
 (0)