Skip to content

Commit

Permalink
chore: upgrade build configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
chengpeiquan committed Sep 3, 2024
1 parent 002bfe1 commit 0371bb6
Show file tree
Hide file tree
Showing 20 changed files with 6,832 additions and 4,762 deletions.
18 changes: 0 additions & 18 deletions .babelrc

This file was deleted.

1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

20 changes: 0 additions & 20 deletions .eslintrc.js

This file was deleted.

36 changes: 34 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
node_modules
# log files
yarn.lock
package-lock.json
examples/*/pnpm-lock.yaml

# build output
dist
pnpm-lock.yaml
lib

# generated types
.astro

# dependencies
node_modules

# logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*


# environment variables
.env
.env.production

# macOS-specific files
.DS_Store

# others
.nyc_output
demo
*.rar
*.zip
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

pnpm exec commit $1
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

pnpm exec lint-staged --concurrent false
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"cSpell.words": ["taze", "tsup"],
"eslint.useFlatConfig": true
}
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<img src="https://img.shields.io/npm/v/vite-plugin-banner?color=56b7ff&label=npm" />
</a>
<a href="https://www.npmjs.com/package/vite-plugin-banner" target="__blank">
<img src="https://img.shields.io/npm/dm/vite-plugin-banner?color=56b7ff&label=" />
<img src="https://img.shields.io/npm/dt/vite-plugin-banner?color=56b7ff&label=" />
</a>
<a href="https://github.com/chengpeiquan/vite-plugin-banner/blob/main/README.md" target="__blank">
<img src="https://img.shields.io/static/v1?label=&message=docs%20%26%20demos&color=56b7ff" />
Expand Down Expand Up @@ -49,7 +49,7 @@ npm install -D vite-plugin-banner
| Plugin Options Type | Description | Example |
| :------------------ | :------------------------------ | :------------------------------------------------------ |
| string | The banner content | [Basic usage](#basic-usage) |
| ContentCallback | See the type declarations below | [Add different banners](#add-different-banners) |
| ContentCallback | See the type declarations below | [Add different banners](#add-different-banners) |
| BannerPluginOptions | See the type declarations below | [Optional parameter format](#optional-parameter-format) |

· Type Declarations:
Expand All @@ -62,19 +62,25 @@ npm install -D vite-plugin-banner
export interface BannerPluginOptions {
/**
* The comment content of the banner
*
* @since ^0.6.0 support for `ContentCallback` types
*/
content: string | ContentCallback

/**
* The output directory from the configuration of Vite.js
* @default 'dist'
*
* @see https://vitejs.dev/config/build-options.html#build-outdir
*
* @default viteConfig.build.outDir
*/
outDir?: string

/**
* Whether to print error messages to the console
*
* @since 0.4.0
*
* @default false
*/
debug?: boolean
Expand All @@ -83,23 +89,29 @@ export interface BannerPluginOptions {
* By default, the validity of the content will be verified.
*
* If set to `false`, no verification will be performed.
*
* @see https://github.com/chengpeiquan/vite-plugin-banner/issues/13
*
* @since 0.5.0
*
* @default true
*/
verify?: boolean
}

/**
* Callback function to get the contents to be injected.(or not inject)
*
* @since 0.6.0
*
* @param fileName - The name of the file currently being processed
*
* @returns
* 1. When a valid string is returned, it will become the banner content
* 2. Returning a Falsy value will skip processing(e.g. `''`, `null`, `undefined`)
*
* @example
*
* ```ts
* content: (fileName: string) => {
* // Or use switch statement
Expand Down Expand Up @@ -165,7 +177,7 @@ import pkg from './package.json'
export default defineConfig({
plugins: [
banner(
`/**\n * name: ${pkg.name}\n * version: v${pkg.version}\n * description: ${pkg.description}\n * author: ${pkg.author}\n * homepage: ${pkg.homepage}\n */`
`/**\n * name: ${pkg.name}\n * version: v${pkg.version}\n * description: ${pkg.description}\n * author: ${pkg.author}\n * homepage: ${pkg.homepage}\n */`,
),
],
})
Expand Down
19 changes: 16 additions & 3 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<img src="https://img.shields.io/npm/v/vite-plugin-banner?color=56b7ff&label=npm" />
</a>
<a href="https://www.npmjs.com/package/vite-plugin-banner" target="__blank">
<img src="https://img.shields.io/npm/dm/vite-plugin-banner?color=56b7ff&label=" />
<img src="https://img.shields.io/npm/dt/vite-plugin-banner?color=56b7ff&label=" />
</a>
<a href="https://github.com/chengpeiquan/vite-plugin-banner/blob/main/README.zh-CN.md" target="__blank">
<img src="https://img.shields.io/static/v1?label=&message=docs%20%26%20demos&color=56b7ff" />
Expand Down Expand Up @@ -57,47 +57,60 @@ npm install --save-dev vite-plugin-banner
````ts
/**
* 来自 `vite.config.[ts|js]` 的一些选项
*
* @since 0.2.0
*/
export interface BannerPluginOptions {
/**
* Banner 的注释内容
*
* @since 从 ^0.6.0 开始支持 `ContentCallback` 类型
*/
content: string | ContentCallback

/**
* Vite.js 配置的输出目录
* @default 'dist'
*
* @see https://cn.vitejs.dev/config/build-options#build-outdir
*
* @default viteConfig.build.outDir
*/
outDir?: string

/**
* 是否将错误信息打印到控制台
*
* @since 0.4.0
*
* @default false
*/
debug?: boolean

/**
* 默认会验证内容的合法性,设置为 `false` 则不验证
*
* @see https://github.com/chengpeiquan/vite-plugin-banner/issues/13
*
* @since 0.5.0
*
* @default true
*/
verify?: boolean
}

/**
* 回调函数获取要注入的内容(或不注入)
*
* @since 0.6.0
*
* @param fileName - 当前正在处理的文件名称
*
* @returns
* 1. 返回有效字符串时,返回值将成为 Banner 的内容
* 2. 返回 Falsy 值将跳过处理(例如 `''`、`null`、`undefined` )
*
* @example
*
* ```ts
* content: (fileName: string) => {
* // 或者使用 `switch` 语句
Expand Down Expand Up @@ -163,7 +176,7 @@ import pkg from './package.json'
export default defineConfig({
plugins: [
banner(
`/**\n * name: ${pkg.name}\n * version: v${pkg.version}\n * description: ${pkg.description}\n * author: ${pkg.author}\n * homepage: ${pkg.homepage}\n */`
`/**\n * name: ${pkg.name}\n * version: v${pkg.version}\n * description: ${pkg.description}\n * author: ${pkg.author}\n * homepage: ${pkg.homepage}\n */`,
),
],
})
Expand Down
16 changes: 16 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @ts-check
import { defineFlatConfig, js, typescript } from '@bassist/eslint'

export default defineFlatConfig([
...js,
...typescript,
{
rules: {
'no-console': 'off',
'require-await': 'off',
},
},
{
ignores: ['dist', 'lib', 'types', 'test'],
},
])
77 changes: 30 additions & 47 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "vite-plugin-banner",
"description": "A banner plugin for Vite. Adds a banner to the top of each generated chunk.",
"version": "0.7.1",
"version": "0.8.0",
"author": "chengpeiquan <[email protected]>",
"type": "module",
"license": "MIT",
"homepage": "https://github.com/chengpeiquan/vite-plugin-banner",
"files": [
Expand All @@ -13,71 +14,53 @@
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
"require": "./dist/index.cjs"
}
},
"publishConfig": {
"registry": "https://registry.npmjs.org/"
},
"scripts": {
"build": "rollup -c rollup.config.ts && esno scripts/buildTypes",
"build": "tsup",
"test": "jest --no-cache --detectOpenHandles",
"lint": "eslint src --ext .js,.ts",
"lint": "eslint .",
"format": "prettier --write .",
"backup": "git add . && git commit -m \"chore: backup\" && git push",
"up": "npx npm-check-updates -u"
"up": "npx taze minor -r -f -w -i",
"prepare": "husky"
},
"repository": {
"type": "git",
"url": "git+https://github.com/chengpeiquan/vite-plugin-banner.git"
"url": "https://github.com/chengpeiquan/vite-plugin-banner"
},
"keywords": [
"vite-plugin",
"vite plugin",
"vite banner"
],
"devDependencies": {
"@babel/core": "^7.18.10",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/preset-env": "^7.18.10",
"@babel/preset-typescript": "^7.18.6",
"@rollup/plugin-babel": "^5.3.1",
"@rollup/plugin-commonjs": "^22.0.2",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.3.0",
"@types/babel__core": "^7.1.19",
"@types/jest": "^28.1.7",
"@types/node": "^18.7.8",
"@typescript-eslint/eslint-plugin": "^5.33.1",
"@typescript-eslint/parser": "^5.33.1",
"babel-jest": "^28.1.3",
"dts-bundle-generator": "^6.12.0",
"eslint": "^8.22.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"esno": "^0.16.3",
"@bassist/commit": "^0.1.1",
"@bassist/eslint": "^0.7.0",
"@bassist/node-utils": "^0.4.1",
"@bassist/tsconfig": "^0.1.1",
"@types/jest": "^28.1.8",
"@types/node": "^20.16.3",
"eslint": "^8.57.0",
"husky": "^9.1.5",
"jest": "^28.1.3",
"lint-staged": "^13.0.3",
"prettier": "^2.7.1",
"rollup": "^2.78.1",
"rollup-plugin-banner2": "^1.2.2",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.33.0",
"lint-staged": "^15.2.10",
"prettier": "^3.3.3",
"ts-jest": "^28.0.8",
"ts-node": "^10.9.1",
"tslib": "^2.4.0",
"typescript": "^4.7.4",
"vite": "^3.0.9",
"yorkie": "^2.0.0"
},
"gitHooks": {
"pre-commit": "lint-staged",
"commit-msg": "esno scripts/verifyCommit.ts"
"tsup": "^8.2.4",
"typescript": "^5.5.4",
"vite": "^5.4.3"
},
"lint-staged": {
"*.js": [
"prettier --write"
],
"*.ts?(x)": [
"prettier --parser=typescript --write"
"*.{js,ts}": [
"prettier --write",
"eslint --fix"
]
}
}
}
Loading

0 comments on commit 0371bb6

Please sign in to comment.