Skip to content

Commit 29aa9e6

Browse files
authored
fix #2230 - prevent babel helpers duplication and condense bundle & types (#2278)
* fix #2230 * fix linting * improve docsearch-js build process, update all rollup configs, delete some deps
1 parent 5142612 commit 29aa9e6

File tree

10 files changed

+161
-160
lines changed

10 files changed

+161
-160
lines changed

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"@babel/plugin-transform-react-jsx": "7.23.4",
4444
"@babel/preset-env": "7.23.5",
4545
"@babel/preset-typescript": "7.23.3",
46+
"@rollup/plugin-babel": "^6.0.4",
4647
"@rollup/plugin-json": "4.1.0",
4748
"@rollup/plugin-node-resolve": "7.1.1",
4849
"@rollup/plugin-replace": "2.3.3",
@@ -62,8 +63,6 @@
6263
"babel-plugin-inline-replace-variables": "1.3.1",
6364
"babel-plugin-module-resolver": "4.0.0",
6465
"bundlesize2": "0.0.31",
65-
"concurrently": "5.3.0",
66-
"cross-env": "7.0.3",
6766
"cssnano": "4.1.10",
6867
"cypress": "9.6.1",
6968
"dotenv": "16.3.1",
@@ -88,8 +87,8 @@
8887
"react": "18.2.0",
8988
"react-dom": "18.2.0",
9089
"rollup": "1.32.1",
91-
"rollup-plugin-babel": "4.4.0",
9290
"rollup-plugin-commonjs": "10.1.0",
91+
"rollup-plugin-dts": "^6.1.1",
9392
"rollup-plugin-filesize": "9.1.2",
9493
"rollup-plugin-license": "3.2.0",
9594
"rollup-plugin-terser": "7.0.2",

packages/docsearch-js/package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@
2222
"jsdelivr": "dist/umd/index.js",
2323
"scripts": {
2424
"build:clean": "rm -rf ./dist",
25-
"build:esm": "cross-env BUILD=esm rollup --config",
26-
"build:types": "tsc -p ./tsconfig.declaration.json --outDir ./dist/esm",
27-
"build:umd": "cross-env BUILD=umd rollup --config",
28-
"build": "yarn build:clean && yarn build:umd && yarn build:esm && yarn build:types",
29-
"on:change": "concurrently \"yarn build:esm\" \"yarn build:types\"",
25+
"build:types": "tsc -p ./tsconfig.declaration.json --outDir ./dist/esm/types",
26+
"build:clean-types": "rm -rf ./dist/esm/types",
27+
"build": "yarn build:clean && yarn build:types && rollup --config && yarn build:clean-types",
28+
"on:change": "yarn build",
3029
"watch": "watch \"yarn on:change\" --ignoreDirectoryPattern \"/dist/\""
3130
},
3231
"dependencies": {
Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,35 @@
11
import replace from '@rollup/plugin-replace';
22

3-
import { plugins } from '../../rollup.base.config';
3+
import { plugins, typesConfig } from '../../rollup.base.config';
44
import { getBundleBanner } from '../../scripts/getBundleBanner';
55

66
import pkg from './package.json';
77

8-
if (!process.env.BUILD) {
9-
throw new Error('The `BUILD` environment variable is required to build.');
10-
}
11-
12-
const output = {
13-
umd: {
14-
file: 'dist/umd/index.js',
15-
format: 'umd',
16-
sourcemap: true,
17-
name: 'docsearch',
18-
banner: getBundleBanner(pkg),
19-
},
20-
esm: {
21-
file: 'dist/esm/index.js',
22-
format: 'es',
23-
sourcemap: true,
24-
banner: getBundleBanner(pkg),
8+
export default [
9+
{
10+
input: 'src/index.ts',
11+
output: [
12+
{
13+
file: 'dist/umd/index.js',
14+
format: 'umd',
15+
sourcemap: true,
16+
name: 'docsearch',
17+
banner: getBundleBanner(pkg),
18+
},
19+
{
20+
file: 'dist/esm/index.js',
21+
format: 'es',
22+
sourcemap: true,
23+
banner: getBundleBanner(pkg),
24+
plugins: [...plugins],
25+
},
26+
],
27+
plugins: [
28+
...plugins,
29+
replace({
30+
'process.env.NODE_ENV': JSON.stringify('production'),
31+
}),
32+
],
2533
},
26-
};
27-
28-
export default {
29-
input: 'src/index.ts',
30-
output: output[process.env.BUILD],
31-
plugins:
32-
process.env.BUILD === 'umd'
33-
? [
34-
...plugins,
35-
replace({
36-
'process.env.NODE_ENV': JSON.stringify('production'),
37-
}),
38-
]
39-
: plugins,
40-
};
34+
typesConfig,
35+
];

packages/docsearch-react/button.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { DocSearchButton } from './dist/esm/DocSearchButton.js';
1+
export { DocSearchButton } from './dist/esm';

packages/docsearch-react/modal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { DocSearchModal } from './dist/esm/DocSearchModal.js';
1+
export { DocSearchModal } from './dist/esm';

packages/docsearch-react/package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@
2525
"jsdelivr": "dist/umd/index.js",
2626
"scripts": {
2727
"build:clean": "rm -rf ./dist",
28-
"build:esm": "babel src --root-mode upward --extensions '.ts,.tsx' --out-dir dist/esm",
29-
"build:types": "tsc -p ./tsconfig.declaration.json --outDir ./dist/esm",
30-
"build:umd": "rollup --config",
31-
"build": "yarn build:clean && yarn build:umd && yarn build:esm && yarn build:types",
32-
"on:change": "concurrently \"yarn build:esm\" \"yarn build:types\"",
28+
"build:clean-types": "rm -rf ./dist/esm/types",
29+
"build:types": "tsc -p ./tsconfig.declaration.json --outDir ./dist/esm/types",
30+
"build": "yarn build:clean && yarn build:types && rollup --config && yarn build:clean-types",
31+
"on:change": "yarn build",
3332
"watch": "watch \"yarn on:change\" --ignoreDirectoryPattern \"/dist/\""
3433
},
3534
"dependencies": {
Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
11
import replace from '@rollup/plugin-replace';
22

3-
import { plugins } from '../../rollup.base.config';
3+
import { plugins, typesConfig } from '../../rollup.base.config';
44
import { getBundleBanner } from '../../scripts/getBundleBanner';
55

66
import pkg from './package.json';
77

8-
export default {
9-
input: 'src/index.ts',
10-
external: ['react', 'react-dom'],
11-
output: {
12-
globals: {
13-
react: 'React',
14-
'react-dom': 'ReactDOM',
15-
},
16-
file: 'dist/umd/index.js',
17-
format: 'umd',
18-
sourcemap: true,
19-
name: pkg.name,
20-
banner: getBundleBanner(pkg),
8+
export default [
9+
{
10+
input: 'src/index.ts',
11+
external: ['react', 'react-dom'],
12+
output: [
13+
{
14+
globals: {
15+
react: 'React',
16+
'react-dom': 'ReactDOM',
17+
},
18+
file: 'dist/umd/index.js',
19+
format: 'umd',
20+
sourcemap: true,
21+
name: pkg.name,
22+
banner: getBundleBanner(pkg),
23+
},
24+
{ dir: 'dist/esm', format: 'es' },
25+
],
26+
plugins: [
27+
...plugins,
28+
replace({
29+
'process.env.NODE_ENV': JSON.stringify('production'),
30+
}),
31+
],
2132
},
22-
plugins: [
23-
...plugins,
24-
replace({
25-
'process.env.NODE_ENV': JSON.stringify('production'),
26-
}),
27-
],
28-
};
33+
typesConfig,
34+
];

packages/website/src/components/ApplyForm.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ function ApplyForm() {
7777
<Card className="uil-m-auto uil-ta-center apply-form">
7878
{state.message.startsWith('Your DocSearch') ? (
7979
<>
80-
<Heading1 className="apply-text">URL Already Submitted!</Heading1>
81-
<br />
82-
<Text
83-
className="uil-pv-8 uil-d-block apply-text"
84-
aria-label="Request has already been processed"
85-
>
86-
{state.message}
87-
</Text>
80+
<Heading1 className="apply-text">URL Already Submitted!</Heading1>
81+
<br />
82+
<Text
83+
className="uil-pv-8 uil-d-block apply-text"
84+
aria-label="Request has already been processed"
85+
>
86+
{state.message}
87+
</Text>
8888
</>
8989
) : (
9090
<>

rollup.base.config.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { babel } from '@rollup/plugin-babel';
12
import json from '@rollup/plugin-json';
23
import resolve from '@rollup/plugin-node-resolve';
34
import replace from '@rollup/plugin-replace';
4-
import babel from 'rollup-plugin-babel';
5+
import dts from 'rollup-plugin-dts';
56
import filesize from 'rollup-plugin-filesize';
67
import { terser } from 'rollup-plugin-terser';
78

@@ -24,3 +25,9 @@ export const plugins = [
2425
showGzippedSize: true,
2526
}),
2627
];
28+
29+
export const typesConfig = {
30+
input: 'dist/esm/types/index.d.ts',
31+
output: [{ file: 'dist/esm/index.d.ts', format: 'es' }],
32+
plugins: [dts()],
33+
};

0 commit comments

Comments
 (0)