Skip to content

Commit 6879407

Browse files
committed
build(lib): Migrate to esbuild and drop UMD support
- Moves from rollup to esbuild for faster compilation. - UMD build is removed in favour of a simpler IIFE. This ends compatibility for old module systems, such as AMD. - Dev workflow is simplified through the use of esbuild's serve command, which takes the place of http-server for our purposes.
1 parent b683f97 commit 6879407

12 files changed

Lines changed: 2091 additions & 3940 deletions

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
node_modules/
33
cypress/videos/
44
dist/*
5-
!dist/.gitkeep

.npmignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
# include whitelist
44
!dist/*.js
55
!dist/types/**/*.d.ts
6-
!css/*.css
6+
!dist/*.css

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ jobs:
1313
include:
1414
- stage: test
1515
before_script: npm run build
16-
script: npm run test:ci
17-
- before_script: npm run build
18-
script: npm run test:lint
16+
script: npm run test
1917
- before_script: npm run build
2018
script: npx bundlesize
2119
- stage: release

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ There's also a Glitch pen [available here](https://priority-plus-demo.glitch.me/
1515

1616
**The short stuff**:
1717

18-
- Vanilla JS, dependency free. Available as an ES6 module, CJS module, or a UMD bundle.
18+
- Vanilla JS, dependency free. Available as an ES6 module, or a drop-in IIFE assigned to the global `priorityPlus`.
1919
- Uses the [`IntersectionObserver` API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API) instead of width-based calculations.
2020
- Toggles the appropriate [WAI-ARIA](https://www.w3.org/WAI/standards-guidelines/aria/) attributes to remain accessible.
2121
- Provides a class hook to style the menu differently when all items are in the overflow/hidden.
@@ -83,9 +83,9 @@ npm install priority-plus
8383
Or use a CDN if you're feeling old-school:
8484

8585
```html
86-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/priority-plus/css/priority-plus.css">
86+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/priority-plus/dist/priority-plus.css">
8787
<!-- Will be available globally as priorityPlus -->
88-
<script defer src="https://cdn.jsdelivr.net/npm/priority-plus/dist/priority-plus.umd.js"></script>
88+
<script defer src="https://cdn.jsdelivr.net/npm/priority-plus/dist/priority-plus.js"></script>
8989
```
9090

9191
## Setup
@@ -106,7 +106,7 @@ You can create a new instance by passing in an `HTMLElement` that is the direct
106106

107107
```css
108108
// Doesn't have to be SASS, just ensure the CSS is included.
109-
@import "node_modules/priority-nav/css/priority-plus";
109+
@import "node_modules/priority-plus/dist/priority-plus";
110110
```
111111

112112
```javascript

cypress.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"baseUrl": "http://127.0.0.1:8080",
2+
"baseUrl": "http://127.0.0.1:8000",
33
"video": false
44
}

dist/.gitkeep

Whitespace-only changes.

package-lock.json

Lines changed: 2043 additions & 3898 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@
44
"description": "A modern implementation of the priority plus navigation pattern.",
55
"type": "module",
66
"module": "dist/priority-plus.esm.js",
7-
"browser": "dist/priority-plus.umd.js",
7+
"browser": "dist/priority-plus.js",
88
"exports": {
99
"import": "./dist/priority-plus.esm.js",
10-
"default": "./dist/priority-plus.umd.js"
10+
"default": "./dist/priority-plus.js"
1111
},
1212
"types": "dist/types/priorityPlus.d.ts",
1313
"scripts": {
14-
"build": "concurrently \"npm:build:lib\" \"npm:build:types\"",
15-
"build:lib": "rollup -c",
14+
"dev": "esbuild src/browser.ts --bundle --sourcemap --format=iife --servedir=www --outdir=www/assets",
15+
"prebuild": "rimraf dist",
16+
"build": "concurrently \"npm:build:*\"",
17+
"build:esm": "esbuild src/priorityPlus.ts --bundle --minify --format=esm --outfile=dist/priority-plus.esm.js",
18+
"build:iife": "esbuild src/browser.ts --bundle --minify --format=iife --outfile=dist/priority-plus.js",
1619
"build:types": "tsc --emitDeclarationOnly --declarationDir dist/types",
17-
"dev": "rollup -c -w",
18-
"test": "concurrently \"npm:serve\" \"cypress run\"",
19-
"test:ci": "npm run serve & wait-on http://localhost:8080 && cypress run",
20+
"test": "npm run test:types && npm run test:lint && npm run test:e2e",
21+
"test:types": "tsc --noEmit",
2022
"test:lint": "tslint -c tslint.json 'src/**/*.ts'",
21-
"test:open": "concurrently \"npm:serve\" \"cypress open\"",
22-
"serve": "http-server -c-1"
23+
"test:e2e": "npm run dev & wait-on http-get://localhost:8000 && cypress run"
2324
},
2425
"repository": {
2526
"type": "git",
@@ -35,27 +36,24 @@
3536
"url": "https://github.com/jayfreestone/priority-plus/issues"
3637
},
3738
"homepage": "https://github.com/jayfreestone/priority-plus#readme",
38-
"dependencies": {
39-
"@babel/core": "^7.10.4",
40-
"@babel/preset-env": "^7.10.4",
41-
"babel-loader": "^8.1.0"
42-
},
39+
"dependencies": {},
4340
"devDependencies": {
44-
"@cypress/webpack-preprocessor": "^5.4.1",
45-
"@types/chai": "^4.2.11",
46-
"@types/mocha": "^7.0.2",
47-
"concurrently": "^5.2.0",
48-
"cypress": "^4.9.0",
49-
"http-server": "^0.12.3",
50-
"rollup": "^2.18.2",
51-
"rollup-plugin-terser": "^6.1.0",
52-
"rollup-plugin-typescript": "^1.0.1",
53-
"ts-loader": "^7.0.5",
54-
"tslib": "^2.0.0",
41+
"@babel/core": "^7.13.14",
42+
"@babel/preset-env": "^7.13.12",
43+
"@cypress/webpack-preprocessor": "^5.6.0",
44+
"@types/chai": "^4.2.15",
45+
"@types/mocha": "^8.2.2",
46+
"babel-loader": "^8.2.2",
47+
"concurrently": "^6.0.0",
48+
"cypress": "^6.8.0",
49+
"esbuild": "^0.11.2",
50+
"rimraf": "^3.0.2",
51+
"ts-loader": "^8.1.0",
52+
"tslib": "^2.1.0",
5553
"tslint": "^6.1.2",
56-
"typescript": "^3.9.6",
57-
"wait-on": "^5.0.1",
58-
"webpack": "^4.43.0"
54+
"typescript": "^4.2.3",
55+
"wait-on": "^5.3.0",
56+
"webpack": "^5.28.0"
5957
},
6058
"keywords": [
6159
"navigation",
@@ -70,6 +68,7 @@
7068
}
7169
],
7270
"release": {
71+
"branches": ["master"],
7372
"plugins": [
7473
"@semantic-release/commit-analyzer",
7574
"@semantic-release/release-notes-generator",
@@ -78,8 +77,7 @@
7877
"@semantic-release/github",
7978
{
8079
"assets": [
81-
"dist/*.js",
82-
"css/*.css"
80+
"dist/**/*"
8381
]
8482
}
8583
]

src/browser.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Wrapper around library which exposes `priorityPlus` as a global
2+
// on `window`. Required as `globalName` will nest the default export
3+
// under `.default`.
4+
// See: https://github.com/evanw/esbuild/issues/869
5+
import lib from './priorityPlus';
6+
// Required so that esbuild spits out the CSS. We don't include it in
7+
// the main `priorityPlus.ts` file since that would result in two files.
8+
import './css/priority-plus.css';
9+
10+
// @ts-ignore
11+
window.priorityPlus = lib;

0 commit comments

Comments
 (0)