Skip to content

Commit 210a4cc

Browse files
committed
refactor: pack with rollup
1 parent 5599f53 commit 210a4cc

8 files changed

Lines changed: 424 additions & 34 deletions

File tree

package.json

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
{
22
"name": "znotify",
3-
"version": "0.7.0",
3+
"version": "0.7.1",
44
"description": "sdk for znotify",
55
"license": "Apache-2.0",
6-
"main": "lib/cjs/index.js",
7-
"typings": "lib/cjs/index.d.ts",
8-
"module": "lib/esm/index.js",
6+
"main": "dist/znotify.js",
7+
"module": "dist/znotify.mjs",
8+
"typings": "dist/znotify.d.ts",
9+
"type": "module",
910
"scripts": {
10-
"build": "run-p 'build:*'",
11-
"build:cjs": "tsc -p tsconfig.cjs.json",
12-
"build:esm": "tsc -p tsconfig.esm.json",
13-
"clean": "rimraf lib",
11+
"build": "rollup -c",
12+
"clean": "rimraf dist",
1413
"prepublish": "run-s clean build",
1514
"test": "jest",
1615
"coverage": "jest --coverage",
@@ -30,17 +29,22 @@
3029
},
3130
"packageManager": "yarn@3.3.0",
3231
"devDependencies": {
32+
"@rollup/plugin-json": "^5.0.2",
3333
"@types/jest": "29.2.4",
3434
"@types/node": "18.11.10",
3535
"@types/qs": "6.9.7",
36+
"esbuild": "^0.16.1",
3637
"jest": "29.3.1",
3738
"npm-run-all": "4.1.5",
3839
"rimraf": "3.0.2",
40+
"rollup": "^3.6.0",
41+
"rollup-plugin-dts": "^5.0.0",
42+
"rollup-plugin-esbuild": "^5.0.0",
3943
"ts-jest": "29.0.3",
4044
"typescript": "4.9.3"
4145
},
4246
"files": [
43-
"lib"
47+
"dist"
4448
],
4549
"engines": {
4650
"node": " >=14.13.1 || >=16.0.0"

rollup.config.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import dts from 'rollup-plugin-dts'
2+
import esbuild from 'rollup-plugin-esbuild'
3+
import json from '@rollup/plugin-json'
4+
5+
/** @type {import('rollup').RollupOptions} */
6+
const jsConfig = {
7+
input: 'src/index.ts',
8+
plugins: [json(), esbuild()],
9+
external: ["qs", "axios"],
10+
output: [
11+
{
12+
file: `dist/znotify.js`,
13+
format: 'cjs',
14+
sourcemap: true,
15+
},
16+
{
17+
file: `dist/znotify.mjs`,
18+
format: 'es',
19+
sourcemap: true,
20+
},
21+
],
22+
}
23+
24+
/** @type {import('rollup').RollupOptions} */
25+
const dtsConfig = {
26+
input: 'src/index.ts',
27+
plugins: [dts()],
28+
output: {
29+
file: `dist/znotify.d.ts`,
30+
format: 'es',
31+
},
32+
}
33+
34+
export default [jsConfig, dtsConfig]

src/client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import axios, {AxiosInstance} from "axios";
22
import {stringify} from 'qs';
33
import {Channels, ChannelType, ClientResponse, Message, MessageOptions, Priority} from "./entity";
44
import {ENDPOINT, isUUID} from "./utils";
5+
import {version} from "../package.json";
56

67
export class Client {
78
private readonly endpoint: string;
@@ -15,7 +16,7 @@ export class Client {
1516
baseURL: this.endpoint,
1617
timeout: 10000,
1718
headers: {
18-
"User-Agent": "znotify-js-sdk/" + require("../package.json").version
19+
"User-Agent": "znotify-js-sdk/" + version
1920
}
2021
})
2122
}

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ import {send} from "./send";
33
export * from './client';
44
export * from './entity';
55
export {send};
6-
export default send;

tsconfig.cjs.json

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

tsconfig.esm.json

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

tsconfig.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
{
22
"compilerOptions": {
3-
"target": "ES6",
4-
"module": "CommonJS",
3+
"target": "ES2021",
4+
"module": "ESNext",
55
"moduleResolution": "Node",
66
"strict": true,
77
"strictPropertyInitialization": true,
88
"declaration": true,
9+
"outDir": "dist/ts",
910
"allowSyntheticDefaultImports": true,
1011
"esModuleInterop": true,
12+
"resolveJsonModule": true,
13+
"removeComments": false,
14+
"sourceMap": true
1115
},
12-
"include": ["src/**/*"]
16+
"include": [
17+
"src"
18+
]
1319
}

0 commit comments

Comments
 (0)