Skip to content

Commit 12c6fb0

Browse files
joshblackcamertron
andauthored
fix(octicons-styled): update how package is output to reduce bundle size (#1027)
* fix(octicons-styled): update how package is output to reduce bundle size * chore: add changeset * chore: update rollup config --------- Co-authored-by: Cameron Dutro <[email protected]>
1 parent a46108d commit 12c6fb0

File tree

4 files changed

+1519
-868
lines changed

4 files changed

+1519
-868
lines changed

.changeset/six-buttons-listen.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/octicons': minor
3+
---
4+
5+
Update the build output to reduce number of generated assets included in the package on npm

lib/octicons_styled/package.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"test": "jest",
2020
"posttest": "npm run ts-test",
2121
"lint": "eslint src script",
22-
"rollup": "rollup -c"
22+
"rollup": "rollup -c --bundleConfigAsCjs"
2323
},
2424
"keywords": [
2525
"GitHub",
@@ -41,13 +41,14 @@
4141
"styled-components": "4.x || 5.x"
4242
},
4343
"devDependencies": {
44+
"@babel/core": "7.24.7",
45+
"@babel/preset-env": "7.24.7",
46+
"@babel/preset-react": "7.24.7",
4447
"@github/prettier-config": "0.0.4",
48+
"@rollup/plugin-babel": "6.0.4",
4549
"@testing-library/jest-dom": "^5.3.0",
4650
"@testing-library/react": "^10.0.2",
4751
"@types/react": "^16.4.6",
48-
"babel-preset-env": "^1.7.0",
49-
"babel-preset-react": "^6.24.1",
50-
"babel-preset-stage-0": "^6.24.1",
5152
"eslint": "^6.5.1",
5253
"eslint-plugin-github": "4.1.3",
5354
"eslint-plugin-jest": "^21.17.0",
@@ -59,9 +60,7 @@
5960
"next": "^11.1.0",
6061
"react": "^16.4.0",
6162
"react-dom": "^16.4.1",
62-
"rollup": "^0.62.0",
63-
"rollup-plugin-babel": "^3.0.5",
64-
"rollup-plugin-commonjs": "^9.1.3",
63+
"rollup": "^4.18.0",
6564
"styled-components": "^5.1.0",
6665
"typescript": "^3.7.5"
6766
},

lib/octicons_styled/rollup.config.js

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import babel from 'rollup-plugin-babel'
2-
import commonjs from 'rollup-plugin-commonjs'
1+
import babel from '@rollup/plugin-babel'
32
// eslint-disable-next-line import/no-namespace
43
import * as octicons from '../octicons_react/dist/index.esm'
54

@@ -11,36 +10,28 @@ export default [
1110
plugins: [
1211
babel({
1312
babelrc: false,
14-
presets: [
15-
[require.resolve('babel-preset-env'), {modules: false}],
16-
require.resolve('babel-preset-stage-0'),
17-
require.resolve('babel-preset-react')
18-
]
19-
}),
20-
commonjs()
13+
presets: [[require.resolve('@babel/preset-env'), {modules: false}], require.resolve('@babel/preset-react')],
14+
babelHelpers: 'inline'
15+
})
2116
],
2217
output: {
2318
file: 'dist/index.umd.js',
2419
format: 'umd',
2520
name: 'reocticons'
2621
}
2722
},
28-
...icons.map(name => ({
29-
input: `src/__generated__/icons/${name}.js`,
23+
{
24+
input: Object.fromEntries(icons.map(name => [`icons/${name}`, `src/__generated__/icons/${name}.js`])),
3025
plugins: [
3126
babel({
3227
babelrc: false,
33-
presets: [
34-
[require.resolve('babel-preset-env'), {modules: false}],
35-
require.resolve('babel-preset-stage-0'),
36-
require.resolve('babel-preset-react')
37-
]
38-
}),
39-
commonjs()
28+
presets: [[require.resolve('@babel/preset-env'), {modules: false}], require.resolve('@babel/preset-react')],
29+
babelHelpers: 'bundled'
30+
})
4031
],
4132
output: {
42-
file: `dist/icons/${name}.js`,
33+
dir: 'dist',
4334
format: 'esm'
4435
}
45-
}))
36+
}
4637
]

0 commit comments

Comments
 (0)