build: 封装 resolve
parent
e180558b25
commit
d57b82c74e
|
@ -38,7 +38,7 @@ pnpm test:watch
|
||||||
- 应该对新功能进行单元测试。
|
- 应该对新功能进行单元测试。
|
||||||
- 应该在文档中添加相关的使用介绍及方法。
|
- 应该在文档中添加相关的使用介绍及方法。
|
||||||
|
|
||||||
## Project Structure
|
## 项目结构
|
||||||
|
|
||||||
```
|
```
|
||||||
src/ - 源代码
|
src/ - 源代码
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
import path from 'node:path';
|
|
||||||
import { readFileSync } from 'node:fs';
|
import { readFileSync } from 'node:fs';
|
||||||
import esbuildPlugin from 'rollup-plugin-esbuild';
|
import esbuildPlugin from 'rollup-plugin-esbuild';
|
||||||
import dtsPlugin from 'rollup-plugin-dts';
|
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 pkg = getPkgJSON();
|
||||||
const inputPath = path.resolve(__dirname, 'src/index.ts');
|
const inputPath = resolve('src/index.ts');
|
||||||
|
|
||||||
const sourceMap = process.env.SOURCE_MAP === 'true';
|
const sourceMap = process.env.SOURCE_MAP === 'true';
|
||||||
const dts = process.env.DTS === 'true';
|
const dts = process.env.DTS === 'true';
|
||||||
|
@ -38,12 +37,12 @@ function buildConfig(format) {
|
||||||
isDts
|
isDts
|
||||||
? [
|
? [
|
||||||
dtsPlugin({
|
dtsPlugin({
|
||||||
tsconfig: path.resolve(__dirname, 'tsconfig.json'),
|
tsconfig: resolve('tsconfig.json'),
|
||||||
}),
|
}),
|
||||||
compleTypePlugin([path.resolve(__dirname, 'global.d.ts')]),
|
compleTypePlugin([resolve('global.d.ts')]),
|
||||||
]
|
]
|
||||||
: esbuildPlugin({
|
: esbuildPlugin({
|
||||||
tsconfig: path.resolve(__dirname, 'tsconfig.json'),
|
tsconfig: resolve('tsconfig.json'),
|
||||||
sourceMap: output.sourcemap,
|
sourceMap: output.sourcemap,
|
||||||
target: 'es2015',
|
target: 'es2015',
|
||||||
minify: true,
|
minify: true,
|
||||||
|
@ -53,10 +52,7 @@ function buildConfig(format) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveOutput(format, isDts) {
|
function resolveOutput(format, isDts) {
|
||||||
return path.resolve(
|
return resolve(distPath, `${pkg.name}${isDts ? '.d.ts' : `.${format}.js`}`);
|
||||||
distPath,
|
|
||||||
`${pkg.name}${isDts ? '.d.ts' : `.${format}.js`}`,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function compleTypePlugin(files) {
|
function compleTypePlugin(files) {
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import path from 'node:path';
|
|
||||||
import readline from 'node:readline';
|
import readline from 'node:readline';
|
||||||
import { __dirname, getPkgJSON } from './utils';
|
import { getPkgJSON, resolve } from './utils';
|
||||||
|
|
||||||
const changelogPath = path.resolve(__dirname, 'CHANGELOG.md');
|
const changelogPath = resolve('CHANGELOG.md');
|
||||||
const releaselogPath = path.resolve(__dirname, 'RELEASELOG.md');
|
const releaselogPath = resolve('RELEASELOG.md');
|
||||||
const { version } = getPkgJSON();
|
const { version } = getPkgJSON();
|
||||||
const versionRE = new RegExp(`^# \\[?${version}\\]?[ (]`);
|
const versionRE = new RegExp(`^# \\[?${version}\\]?[ (]`);
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ export const require = createRequire(import.meta.url);
|
||||||
export const pkgPath = path.resolve(__dirname, 'package.json');
|
export const pkgPath = path.resolve(__dirname, 'package.json');
|
||||||
export const distPath = path.resolve(__dirname, 'dist');
|
export const distPath = path.resolve(__dirname, 'dist');
|
||||||
|
|
||||||
|
export const resolve = (...paths) => path.resolve(__dirname, ...paths);
|
||||||
export const exec = (command, options) =>
|
export const exec = (command, options) =>
|
||||||
execSync(command, { stdio: 'inherit', ...(options ?? {}) });
|
execSync(command, { stdio: 'inherit', ...(options ?? {}) });
|
||||||
export const getPkgJSON = () => require(pkgPath);
|
export const getPkgJSON = () => require(pkgPath);
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
import path from 'node:path';
|
|
||||||
import { defineConfig } from 'vitest/config';
|
import { defineConfig } from 'vitest/config';
|
||||||
import { __dirname } from './scripts/utils';
|
import { __dirname, resolve } from './scripts/utils';
|
||||||
|
|
||||||
const resolve = (...paths) => path.resolve(__dirname, ...paths);
|
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
test: {
|
test: {
|
||||||
|
|
Loading…
Reference in New Issue