Skip to content

Commit 589c27d

Browse files
committed
setup tsdown for building
1 parent d461bbb commit 589c27d

File tree

3 files changed

+44
-11
lines changed

3 files changed

+44
-11
lines changed

.vscode/settings.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
{
22
"cSpell.words": [
3+
"backquote",
4+
"biomejs",
5+
"coord",
36
"decos",
4-
"helpfeel",
7+
"fuga",
58
"gyazo",
6-
"coord",
7-
"progfay",
8-
"scrapbox",
9-
"backquote",
9+
"helpfeel",
1010
"hoge",
11-
"fuga",
1211
"piyo",
12+
"progfay",
13+
"scrapbox",
1314
"tsbuildinfo",
14-
"biomejs"
15+
"tsdown"
1516
],
1617
"editor.defaultFormatter": "biomejs.biome",
1718
"editor.formatOnSave": true

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"main": "./out/index.cjs",
1010
"module": "./out/index.mjs",
11-
"types": "./out/index.d.ts",
11+
"types": "./out/index.d.mts",
1212
"unpkg": "./out/scrapbox-parser.umd.js",
1313
"exports": {
1414
"types": "./out/index.d.ts",
@@ -24,9 +24,7 @@
2424
},
2525
"scripts": {
2626
"prebuild": "node -e 'fs.rmSync(`out`, {recursive:true, force:true})'",
27-
"build": "run-p build:*",
28-
"build:types": "tsc -p ./tsconfig.json",
29-
"build:vite": "vite build",
27+
"build": "tsdown",
3028
"prepare": "npm run build",
3129
"test": "node --experimental-default-config-file --test --experimental-test-coverage",
3230
"test:update": "npm test -- --experimental-test-snapshots",

tsdown.config.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { resolve } from "node:path";
2+
import { defineConfig, type Options } from "tsdown";
3+
4+
type ModuleFormat = Extract<Options["format"], string>;
5+
6+
const FORMAT_ENTRY_FILE_NAMES_MAP = {
7+
es: "[name].mjs",
8+
esm: "[name].mjs",
9+
module: "[name].mjs",
10+
cjs: "[name].cjs",
11+
commonjs: "[name].cjs",
12+
umd: "scrapbox-parser.umd.js",
13+
iife: undefined,
14+
} as const satisfies Record<ModuleFormat, string | undefined>;
15+
16+
export default defineConfig([
17+
{
18+
format: ["es", "cjs", "umd"],
19+
entry: resolve(import.meta.dirname, "src/index.ts"),
20+
dts: true,
21+
minify: true,
22+
sourcemap: true,
23+
platform: "neutral",
24+
outDir: "out",
25+
clean: true,
26+
outputOptions: ({ format, entryFileNames, ...options }) => ({
27+
...options,
28+
format,
29+
name: "ScrapboxParser",
30+
entryFileNames:
31+
(format && FORMAT_ENTRY_FILE_NAMES_MAP[format]) ?? entryFileNames,
32+
}),
33+
},
34+
]);

0 commit comments

Comments
 (0)