build: move to esm (wip)

This commit is contained in:
Justineo
2024-04-16 13:02:13 +08:00
parent 002b2f2701
commit d00aa090a6
5 changed files with 25 additions and 19 deletions

View File

@ -71,7 +71,12 @@ const builds = [
sourcemap: true sourcemap: true
} }
] ]
}, }
];
export default [
...builds.map(options => configBuild(options, false)),
...builds.map(options => configBuild(options, true)),
{ {
input: "src/index.ts", input: "src/index.ts",
plugins: [ plugins: [
@ -90,8 +95,3 @@ const builds = [
} }
} }
]; ];
export default [
...builds.map(options => configBuild(options, false)),
...builds.map(options => configBuild(options, true))
];

View File

@ -1,15 +1,8 @@
import { readFileSync, writeFileSync } from "node:fs"; import { readFileSync, writeFileSync } from "node:fs";
import { resolve, dirname } from "node:path";
import { fileURLToPath } from "node:url";
import commentMark from "comment-mark"; import commentMark from "comment-mark";
import { getPackageMeta, resolvePath } from "./utils";
function resolvePath(...parts) { const { name, version } = getPackageMeta();
return resolve(dirname(fileURLToPath(import.meta.url)), ...parts);
}
const { name, version } = JSON.parse(
readFileSync(resolvePath("..", "package.json"), "utf8")
);
const CDN_PREFIX = "https://cdn.jsdelivr.net/npm/"; const CDN_PREFIX = "https://cdn.jsdelivr.net/npm/";
@ -45,7 +38,7 @@ const scripts = {
}; };
const README_FILES = ["README.md", "README.zh-Hans.md"].map(name => const README_FILES = ["README.md", "README.zh-Hans.md"].map(name =>
resolvePath("..", name) resolvePath(import.meta.url, "..", name)
); );
README_FILES.forEach(file => { README_FILES.forEach(file => {

View File

@ -1,8 +1,8 @@
/* eslint-disable @typescript-eslint/no-var-requires */ /* eslint-disable @typescript-eslint/no-var-requires */
import path from "node:path";
import fs from "node:fs"; import fs from "node:fs";
import { resolvePath } from "./utils.js";
const packageFile = path.resolve(__dirname, "../package.json"); const packageFile = resolvePath(import.meta.url, "../package.json");
const typesPaths = { const typesPaths = {
3: "dist/index.d.ts", 3: "dist/index.d.ts",

13
scripts/utils.js Normal file
View File

@ -0,0 +1,13 @@
import { readFileSync } from "node:fs";
import { resolve, dirname } from "node:path";
import { fileURLToPath } from "node:url";
export function resolvePath(url, ...parts) {
return resolve(dirname(fileURLToPath(url)), ...parts);
}
export function getPackageMeta() {
return JSON.parse(
readFileSync(resolvePath(import.meta.url, "/package.json"), "utf8")
);
}

View File

@ -1,5 +1,5 @@
import { init } from "echarts/core"; import { init } from "echarts/core";
import type { Ref } from "vue"; import type { Ref } from "vue-demi";
import type { SetOptionOpts, ECElementEvent, ElementEvent } from "echarts"; import type { SetOptionOpts, ECElementEvent, ElementEvent } from "echarts";
export type Injection<T> = T | null | Ref<T | null> | { value: T | null }; export type Injection<T> = T | null | Ref<T | null> | { value: T | null };