Skip to content

Commit 3897c1f

Browse files
Replace Rollup with Vite
1 parent fad7140 commit 3897c1f

File tree

8 files changed

+388
-76
lines changed

8 files changed

+388
-76
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
**/dist/*
2-
**/site/bundles/
2+
**/site/*
33
*.js.map
44
*.pyc
55
.DS_Store

package.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,9 @@
2424
"@rollup/plugin-node-resolve": "11.2.1",
2525
"@rollup/plugin-replace": "4.0.0",
2626
"@squoosh/cli": "0.6.3",
27-
"concurrently": "7.1.0",
28-
"dhost": "0.3.5",
29-
"rollup": "2.75.7",
30-
"rollup-plugin-commonjs": "10.0.1",
31-
"rollup-plugin-esm-import-to-url": "2.1.0",
32-
"rollup-plugin-livereload": "2",
33-
"rollup-plugin-node-resolve": "5.2.0",
34-
"rollup-plugin-replace": "2.2.0",
3527
"tslib": "2.1.0",
3628
"typescript": "5.1.6",
29+
"vite": "^4.5.0",
3730
"wireit": "0.7.1"
3831
},
3932
"packageManager": "yarn@3.2.1"

packages/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "trapeze",
33
"version": "1.2.0",
44
"description": "A Preact library for paginated experiences, like slide decks and surveys.",
5+
"typescript": "./src/preact.tsx",
56
"module": "./dist/preact.js",
67
"types": "./dist/preact.d.ts",
78
"scripts": {

packages/demos/package.json

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,25 @@
33
"name": "trapeze-demos",
44
"version": "0.0.0",
55
"scripts": {
6-
"start": "yarn run -TB concurrently \"yarn run build:tsc --watch\" \"rollup --config ./rollup.config.js --watch\" \"dhost site --bind-all\"",
6+
"start": "yarn run -TB wireit",
77
"build": "yarn run -TB wireit",
88
"build:tsc": "yarn run -TB wireit",
9-
"build:bundle": "yarn run -TB wireit"
9+
"build:gen-html": "yarn run -TB wireit",
10+
"build:site": "yarn run -TB wireit"
1011
},
1112
"wireit": {
13+
"start": {
14+
"service": true,
15+
"command": "vite serve",
16+
"files": [
17+
"vite.config.js"
18+
]
19+
},
1220
"build": {
1321
"dependencies": [
1422
"build:tsc",
15-
"build:bundle"
23+
"build:gen-html",
24+
"build:site"
1625
]
1726
},
1827
"build:tsc": {
@@ -24,7 +33,7 @@
2433
"../../tsconfig.common.json"
2534
],
2635
"output": [
27-
"dist/**",
36+
"dist/**/*.js",
2837
".tsbuildinfo"
2938
],
3039
"packageLocks": [
@@ -34,22 +43,33 @@
3443
"../core:build"
3544
]
3645
},
37-
"build:bundle": {
38-
"command": "rollup --config ./rollup.config.js",
46+
"build:gen-html": {
47+
"command": "sed 's/mount.tsx/mount.js/' src/index.html > dist/index.html",
48+
"files": [
49+
"src/index.html"
50+
],
51+
"output": [
52+
"dist/index.html"
53+
]
54+
},
55+
"build:site": {
56+
"command": "vite build",
3957
"clean": true,
4058
"files": [
59+
"dist/**/index.html",
4160
"dist/**/*.js",
42-
"rollup.config.js"
61+
"vite.config.js"
4362
],
4463
"output": [
45-
"site/mount.js",
64+
"site/**/*",
4665
".tsbuildinfo"
4766
],
4867
"packageLocks": [
4968
"yarn.lock"
5069
],
5170
"dependencies": [
52-
"build:tsc"
71+
"build:tsc",
72+
"build:gen-html"
5373
]
5474
}
5575
},

packages/demos/rollup.config.js

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

packages/demos/site/index.html renamed to packages/demos/src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
</body>
4949
<script
5050
type = 'module'
51-
src = '/bundles/mount.js'
51+
src = 'mount.tsx'
5252
></script>
5353
</html>
5454

packages/demos/vite.config.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { defineConfig } from 'vite'
2+
3+
// Before vite, we used wireit + tsc for building. Because tsc checks all the
4+
// types before generating JS, the delay between editing a file and seeing a
5+
// change in-browser got to be too long. vite short-circuits type checking,
6+
// effectively stripping the types and presenting the result in the browser as
7+
// quickly as possible.
8+
//
9+
// The config below provides vite with raw TypeScript for fast iteration cycles
10+
// when running the dev server, but with tsc-checked JavaScript otherwise.
11+
//
12+
// This is my first try using vite. We may later find that there's a better way
13+
// to incorporate type-checking (maybe wireit + tsc isn't needed anymore). For
14+
// now, this gets us the speed of vite's dev cycles without changing how our
15+
// packages are generated.
16+
17+
export default defineConfig(
18+
({ command }) => ({
19+
// This allows us to colocate the HTML file with its scripts without getting
20+
// the folder name baked into the HTML path.
21+
root: command === 'serve'
22+
? 'src'
23+
: 'dist',
24+
25+
resolve: {
26+
mainFields: command === 'serve'
27+
? ['typescript', 'browser', 'module']
28+
: ['browser', 'module'],
29+
},
30+
build: {
31+
// ./dist/../site == ./site
32+
outDir: '../site',
33+
},
34+
})
35+
);

0 commit comments

Comments
 (0)