Skip to content

Commit

Permalink
feat(build): add index files to bundles (#223)
Browse files Browse the repository at this point in the history
This allows more visually appealing imports when used with bundlers:
```typescript
// Old, but still works:
import * as vis from "vis-network/standalone/esm/vis-network";

// New, achieving the same result (ESM):
import * as vis from "vis-network/standalone";

// ESM explicitly:
import * as vis from "vis-network/standalone/esm";

// UMD explicitly:
import * as vis from "vis-network/standalone/umd";
```

This partially works in HTML but the old way is preferred (less requests,
library name in dev tools and better compatibility):
```html
<!-- Old, still works. Recommended. -->
<script
  type="text/javascript"
  src="https://unpkg.com/vis-network/standalone/umd/vis-network.min.js"
></script>

<!-- New, works but has issues. Not recommended. -->
<script
  type="module"
  src="https://unpkg.com/vis-network/standalone/esm"
></script>

<!-- New, doesn't work. -->
<script
  type="text/javascript"
  src="https://unpkg.com/vis-network/standalone/umd"
></script>
```
  • Loading branch information
Thomaash authored and yotamberk committed Nov 10, 2019
1 parent e3ef6a7 commit c4ff269
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions dev-lib/bundle-css.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "./vis-network.css";
1 change: 1 addition & 0 deletions dev-lib/bundle-esm-index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./esm";
1 change: 1 addition & 0 deletions dev-lib/bundle-vis-network-index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./vis-network";
40 changes: 40 additions & 0 deletions rollup.build.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,46 @@ export default [].concat.apply(
src: `./dev-lib/bundle-${variant}.d.ts`,
dest: ".",
rename: umdFileWithoutExt + ".d.ts"
},
{
src: "./dev-lib/bundle-esm-index.d.ts",
dest: ".",
rename: `${variant}/index.d.ts`
},
{
src: "./dev-lib/bundle-esm-index.d.ts",
dest: ".",
rename: `${variant}/index.js`
},
{
src: "./dev-lib/bundle-vis-network-index.d.ts",
dest: ".",
rename: `${variant}/esm/index.d.ts`
},
{
src: "./dev-lib/bundle-vis-network-index.d.ts",
dest: ".",
rename: `${variant}/esm/index.js`
},
{
src: "./dev-lib/bundle-vis-network-index.d.ts",
dest: ".",
rename: `${variant}/umd/index.d.ts`
},
{
src: "./dev-lib/bundle-vis-network-index.d.ts",
dest: ".",
rename: `${variant}/umd/index.js`
},
{
src: "./dev-lib/bundle-css.d.ts",
dest: ".",
rename: "styles/index.d.ts"
},
{
src: "./dev-lib/bundle-css.d.ts",
dest: ".",
rename: "styles/index.js"
}
]
}),
Expand Down

0 comments on commit c4ff269

Please sign in to comment.