Skip to content

Commit 518b67a

Browse files
committed
Better build scripting
1 parent 5c3ffa9 commit 518b67a

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

.tokeignore

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

build-all.mjs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env zx
2+
3+
await $`npm run lint`
4+
await $`npm run check`
5+
await $`npm run build`
6+
await $`npx svelte-package`
7+
const out = await $`npx vite build -c vite.dist.config.js`
8+
9+
// Calculate stats
10+
const sizes = out.stdout
11+
.split('\n')
12+
.find((i) => i.includes('index.umd.cjs'))
13+
.split(' ')
14+
.filter((i) => !isNaN(parseFloat(i)))
15+
const cloc = JSON.parse(await $`npx cloc src/lib --json`).SUM.code.toString()
16+
17+
// Write stats into `/build`
18+
const shields = { schemaVersion: 1, color: 'blue' }
19+
await fs.writeJson('build/_min.json', { ...shields, label: 'minified', message: `${sizes[0]} kB` })
20+
await fs.writeJson('build/_gzip.json', { ...shields, label: 'gzipped', message: `${sizes[1]} kB` })
21+
await fs.writeJson('build/_loc.json', { ...shields, label: 'lines of code', message: cloc })
22+
23+
// Prepare `/dist`
24+
const pkg = await fs.readJson('package.json')
25+
pkg.scripts = undefined
26+
await fs.writeJson('dist/package.json', pkg, { spaces: 2 })
27+
await fs.copy('README.md', 'dist/README.md')
28+
await fs.copy('LICENSE', 'dist/LICENSE')
29+
await $`cd dist && npx publint`
30+
31+
echo`
32+
To deploy the demo, run:
33+
$ npx gh-pages -d build -t -f
34+
35+
To publish into npm, run:
36+
$ cd dist && npm publish --access public
37+
`

vite.dist.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ export default defineConfig({
1313
})
1414
],
1515
build: {
16-
outDir: './package/dist',
16+
outDir: './dist/dist',
1717
minify: 'terser',
1818
lib: {
1919
entry: './src/lib/index.js',
2020
name: 'window',
21-
fileName: (format) => `index.${format}.js`
21+
fileName: (format) => `index.${format === 'umd' ? 'umd.cjs' : 'es.js'}`
2222
},
2323
rollupOptions: {
2424
output: {

0 commit comments

Comments
 (0)