Skip to content

Commit 5fddaea

Browse files
committed
Build with vite to maintain cjs compatability
1 parent a0558e2 commit 5fddaea

5 files changed

Lines changed: 85 additions & 62 deletions

File tree

examples/browser/index.html

Lines changed: 0 additions & 53 deletions
This file was deleted.

index.html

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<title>Tide Predictor in the browser</title>
6+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" />
7+
</head>
8+
9+
<body>
10+
<div class="container">
11+
<h1>High/low tides for Monterey, CA</h1>
12+
<table class="table">
13+
<thead>
14+
<tr>
15+
<th>Time</th>
16+
<th>High/Low</th>
17+
<th>Level (meters)</th>
18+
</tr>
19+
<tbody id="tides"></tbody>
20+
</thead>
21+
</table>
22+
</div>
23+
24+
<script type="module">
25+
import tidePredictor from './src/index.js'
26+
27+
(() => {
28+
fetch('https://api.tidesandcurrents.noaa.gov/mdapi/prod/webapi/stations/9413450/harcon.json?units=metric')
29+
.then(response => {
30+
return response.json()
31+
})
32+
.then(harmonics => {
33+
const start = new Date()
34+
const end = new Date(start.getTime() + (10 * 24 * 60 * 60 * 1000))
35+
36+
const highLow = tidePredictor(harmonics.HarmonicConstituents).getExtremesPrediction({ start, end })
37+
38+
highLow.forEach(level => {
39+
const tableRow = document.createElement('tr')
40+
tableRow.innerHTML = `
41+
<td>${level
42+
.time}</td>
43+
<td>${level
44+
.label}</td>
45+
<td>${level
46+
.level}</td>
47+
`
48+
document
49+
.getElementById('tides')
50+
.appendChild(tableRow)
51+
})
52+
})
53+
})()
54+
</script>
55+
</body>
56+
57+
</html>

package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
"author": "Kevin Miller <keveemiller@gmail.com>",
77
"license": "MIT",
88
"type": "module",
9+
"main": "dist/index.umd.cjs",
910
"exports": {
1011
".": {
12+
"types": "./dist/index.d.ts",
1113
"import": "./dist/index.js",
12-
"types": "./dist/index.d.ts"
14+
"require": "./dist/index.umd.cjs"
1315
}
1416
},
1517
"files": [
@@ -25,11 +27,14 @@
2527
"mocha": "^10.0.0",
2628
"npm-run-all": "^4.1.5",
2729
"tsx": "^4.7.0",
28-
"typescript": "^5.3.3"
30+
"typescript": "^5.3.3",
31+
"vite": "^7.2.7",
32+
"vite-plugin-dts": "^4.5.4"
2933
},
3034
"scripts": {
31-
"build": "tsc",
32-
"test": "mocha --require tsx --extension ts --extension js --recursive",
35+
"dev": "vite",
36+
"build": "vite build",
37+
"test": "tsc && mocha --require tsx --extension ts --extension js --recursive",
3338
"lint": "eslint ./src --ext .ts,.tsx,.js",
3439
"coverage": "c8 --reporter=lcov mocha --require tsx --extension ts --extension js --recursive",
3540
"ci": "run-s lint build coverage",

tsconfig.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,13 @@
66
"moduleResolution": "bundler",
77
"allowSyntheticDefaultImports": true,
88
"esModuleInterop": true,
9-
"declaration": true,
10-
"declarationMap": true,
11-
"sourceMap": true,
12-
"outDir": "./dist",
139
"rootDir": "./src",
1410
"strict": true,
1511
"skipLibCheck": true,
1612
"forceConsistentCasingInFileNames": true,
1713
"resolveJsonModule": true,
1814
"allowImportingTsExtensions": false,
19-
"noEmit": false
15+
"noEmit": true
2016
},
2117
"include": ["src/**/*"],
2218
"exclude": ["node_modules", "dist", "test"]

vite.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { dirname, resolve } from 'node:path'
2+
import { fileURLToPath } from 'node:url'
3+
import { defineConfig } from 'vite'
4+
import dts from 'vite-plugin-dts'
5+
6+
const __dirname = dirname(fileURLToPath(import.meta.url))
7+
8+
export default defineConfig({
9+
build: {
10+
lib: {
11+
entry: resolve(__dirname, 'src/index.ts'),
12+
name: 'TidePredictor',
13+
fileName: 'index'
14+
},
15+
sourcemap: true
16+
},
17+
plugins: [dts({ rollupTypes: true })]
18+
})

0 commit comments

Comments
 (0)