build: 封装 resolve

pull/41/head
zjx0905 2023-04-10 15:12:28 +08:00
parent e180558b25
commit d57b82c74e
5 changed files with 12 additions and 19 deletions

View File

@ -38,7 +38,7 @@ pnpm test:watch
- 应该对新功能进行单元测试。
- 应该在文档中添加相关的使用介绍及方法。
## Project Structure
## 项目结构
```
src/ - 源代码

View File

@ -1,11 +1,10 @@
import path from 'node:path';
import { readFileSync } from 'node:fs';
import esbuildPlugin from 'rollup-plugin-esbuild';
import dtsPlugin from 'rollup-plugin-dts';
import { __dirname, distPath, getPkgJSON } from './scripts/utils.js';
import { __dirname, distPath, getPkgJSON, resolve } from './scripts/utils.js';
const pkg = getPkgJSON();
const inputPath = path.resolve(__dirname, 'src/index.ts');
const inputPath = resolve('src/index.ts');
const sourceMap = process.env.SOURCE_MAP === 'true';
const dts = process.env.DTS === 'true';
@ -38,12 +37,12 @@ function buildConfig(format) {
isDts
? [
dtsPlugin({
tsconfig: path.resolve(__dirname, 'tsconfig.json'),
tsconfig: resolve('tsconfig.json'),
}),
compleTypePlugin([path.resolve(__dirname, 'global.d.ts')]),
compleTypePlugin([resolve('global.d.ts')]),
]
: esbuildPlugin({
tsconfig: path.resolve(__dirname, 'tsconfig.json'),
tsconfig: resolve('tsconfig.json'),
sourceMap: output.sourcemap,
target: 'es2015',
minify: true,
@ -53,10 +52,7 @@ function buildConfig(format) {
}
function resolveOutput(format, isDts) {
return path.resolve(
distPath,
`${pkg.name}${isDts ? '.d.ts' : `.${format}.js`}`,
);
return resolve(distPath, `${pkg.name}${isDts ? '.d.ts' : `.${format}.js`}`);
}
function compleTypePlugin(files) {

View File

@ -1,10 +1,9 @@
import fs from 'node:fs';
import path from 'node:path';
import readline from 'node:readline';
import { __dirname, getPkgJSON } from './utils';
import { getPkgJSON, resolve } from './utils';
const changelogPath = path.resolve(__dirname, 'CHANGELOG.md');
const releaselogPath = path.resolve(__dirname, 'RELEASELOG.md');
const changelogPath = resolve('CHANGELOG.md');
const releaselogPath = resolve('RELEASELOG.md');
const { version } = getPkgJSON();
const versionRE = new RegExp(`^# \\[?${version}\\]?[ (]`);

View File

@ -8,6 +8,7 @@ export const require = createRequire(import.meta.url);
export const pkgPath = path.resolve(__dirname, 'package.json');
export const distPath = path.resolve(__dirname, 'dist');
export const resolve = (...paths) => path.resolve(__dirname, ...paths);
export const exec = (command, options) =>
execSync(command, { stdio: 'inherit', ...(options ?? {}) });
export const getPkgJSON = () => require(pkgPath);

View File

@ -1,8 +1,5 @@
import path from 'node:path';
import { defineConfig } from 'vitest/config';
import { __dirname } from './scripts/utils';
const resolve = (...paths) => path.resolve(__dirname, ...paths);
import { __dirname, resolve } from './scripts/utils';
export default defineConfig({
test: {