Skip to content

Commit 7767b37

Browse files
committed
Add /*#__PURE__*/ annotations to hint Terser for tree-shaking
Webpack is more conservative in terms of dead code elimination compared to Rollup, which causes it to bundle all the icons even when they are not used. This patch annotate the `genIcon` and `Object.keys` function as pure to give Terser a hint that it is in fact side effect free. Closes #1.
1 parent ba671c2 commit 7767b37

File tree

7 files changed

+1208
-1211
lines changed

7 files changed

+1208
-1211
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Include the scripts from CDN as follows:
9898

9999
```html
100100
<script src="https://unpkg.com/vue@3.0.4"></script>
101-
<script src="https://unpkg.com/bootstrap-icons-vue@0.4.0"></script>
101+
<script src="https://unpkg.com/bootstrap-icons-vue@0.4.1"></script>
102102
```
103103

104104
Vue 3 does not have a global application instance, so it is not possible to install the icons components automatically. Instead the browser build exports a plugin `BootstrapIconsVue` to be installed:
@@ -111,6 +111,6 @@ app.mount('#app');
111111

112112
### Development
113113

114-
Install dependencies with `yarn install` then generate icon files with `yarn build`. Test them in cdn mode with `yarn dev:cdn` or vite mode with `yarn dev:vite`.
114+
Install dependencies with `yarn install` then generate icon files with `yarn build`. To test the browser build, run `yarn dev:cdn`. With the vite app, first link the library by running `yarn link` in this directory, then `yarn link bootstrap-icons-vue` in `./dev-vite`, finally run `yarn dev:vite` back in this directory.
115115

116116
[Bootstrap Icons]: https://icons.getbootstrap.com/

dev-vite/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"build": "vite build"
77
},
88
"dependencies": {
9-
"bootstrap-icons-vue": "file:..",
109
"vue": "^3.0.4"
1110
},
1211
"devDependencies": {

dev-vite/yarn.lock

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,6 @@ bluebird@^3.7.2:
441441
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f"
442442
integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==
443443

444-
"bootstrap-icons-vue@file:..":
445-
version "0.4.0"
446-
447444
brace-expansion@^1.1.7:
448445
version "1.1.11"
449446
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bootstrap-icons-vue",
3-
"version": "0.4.0",
3+
"version": "0.4.1",
44
"description": "Bootstrap icons as Vue components.",
55
"author": "Thomas Ip <thomas@ipthomas.com>",
66
"license": "MIT",
@@ -41,5 +41,6 @@
4141
},
4242
"files": [
4343
"/dist"
44-
]
44+
],
45+
"sideEffects": false
4546
}

src/codegen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { genIcon } from './utils';
1313
`;
1414

1515
const iconComponentTemplate = `\
16-
export const {{componentName}} = genIcon(
16+
export const {{componentName}} = /*#__PURE__*/ genIcon(
1717
'{{componentName}}',
1818
'{{svgContent}}'
1919
);`;

src/icons.ts

Lines changed: 1201 additions & 1201 deletions
Large diffs are not rendered by default.

src/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ export const BootstrapIconsPlugin: Plugin = {
99
},
1010
};
1111

12-
export const iconNames = Object.keys(icons);
12+
export const iconNames = /*#__PURE__*/ Object.keys(icons);

0 commit comments

Comments
 (0)