Skip to content

Commit 3f6be3c

Browse files
committed
update to rollup.config.js - add "pure_getters": true and "emca": 2015 to terser plugin settings to reduce bundle size; run final step to clean-up "data-testid" attributes from source code as final step in bundling using plugin-replace
1 parent 899cc59 commit 3f6be3c

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
"@babel/cli": "^7.13.10",
4141
"@babel/core": "^7.13.10",
4242
"@babel/plugin-proposal-object-rest-spread": "^7.13.8",
43-
"@babel/plugin-proposal-optional-chaining": "^7.13.8",
43+
"@babel/plugin-proposal-optional-chaining": "^7.13.12",
4444
"@babel/plugin-transform-runtime": "^7.13.10",
45-
"@babel/preset-env": "^7.13.10",
45+
"@babel/preset-env": "^7.13.12",
4646
"@babel/preset-react": "^7.12.13",
4747
"@babel/preset-typescript": "^7.13.0",
4848
"@babel/runtime": "^7.13.10",
@@ -62,8 +62,8 @@
6262
"@types/react-dom": "^17.0.2",
6363
"@types/react-window": "^1.8.2",
6464
"@types/styled-components": "^5.1.9",
65-
"@typescript-eslint/eslint-plugin": "^4.18.0",
66-
"@typescript-eslint/parser": "^4.18.0",
65+
"@typescript-eslint/eslint-plugin": "^4.19.0",
66+
"@typescript-eslint/parser": "^4.19.0",
6767
"babel-jest": "^26.6.3",
6868
"babel-loader": "^8.2.2",
6969
"babel-plugin-styled-components": "^1.12.0",
@@ -86,7 +86,7 @@
8686
"react-toastify": "^7.0.3",
8787
"react-window": "^1.8.6",
8888
"rimraf": "^3.0.2",
89-
"rollup": "^2.42.2",
89+
"rollup": "^2.42.3",
9090
"rollup-plugin-terser": "^7.0.2",
9191
"styled-components": "^5.2.1",
9292
"typescript": "^4.2.3"

rollup.config.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ const terserPlugin = terser({
2424
format: {
2525
preserve_annotations: true,
2626
},
27+
compress: {
28+
ecma: 2015,
29+
pure_getters: true,
30+
},
2731
});
2832

2933
/**
@@ -34,6 +38,14 @@ const replacePlugin = replace({
3438
'process.env.NODE_ENV': JSON.stringify('production'),
3539
});
3640

41+
// Remove data-testid attribute (since undefined in non-test environments)
42+
// Perform as final step in transformed, bundled code (for esm and cjs builds)
43+
const removeTestIdPlugin = replace({
44+
preventAssignment: true,
45+
',"data-testid":undefined': '',
46+
delimiters: ['', ''],
47+
});
48+
3749
/**
3850
* Babel Plugin config (differs from project's babel.config.js)
3951
*/
@@ -48,11 +60,11 @@ const babelPlugin = (useESModules = true) => {
4860
exclude: 'node_modules/**',
4961
extensions: [...DEFAULT_EXTENSIONS, '.ts', '.tsx'],
5062
presets: [
51-
['@babel/preset-env', { targets, loose: false, bugfixes: true }],
52-
['@babel/preset-react', { runtime: 'classic' }],
63+
['@babel/preset-env', {targets, loose: false, bugfixes: true}],
64+
['@babel/preset-react', {runtime: 'classic'}],
5365
],
5466
plugins: [
55-
['@babel/plugin-transform-runtime', { useESModules }],
67+
['@babel/plugin-transform-runtime', {useESModules}],
5668
'@babel/plugin-proposal-optional-chaining',
5769
[
5870
'babel-plugin-styled-components',
@@ -84,6 +96,7 @@ export default [
8496
typescript(),
8597
babelPlugin(false),
8698
terserPlugin,
99+
removeTestIdPlugin
87100
],
88101
},
89102

@@ -101,6 +114,7 @@ export default [
101114
typescript(),
102115
babelPlugin(),
103116
terserPlugin,
117+
removeTestIdPlugin
104118
],
105119
},
106120

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"strict": true,
99
"skipLibCheck": true,
1010
"noUnusedLocals": true,
11-
"removeComments": true,
11+
"removeComments": false,
1212
"esModuleInterop": true,
1313
"isolatedModules": true,
1414
"experimentalDecorators": true,

0 commit comments

Comments
 (0)