Skip to content

Commit 7b72e98

Browse files
authored
Merge pull request #8 from chengpeiquan/develop
Develop
2 parents bb7aad4 + 5771923 commit 7b72e98

31 files changed

+7481
-193
lines changed

.babelrc

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
{
66
"modules": false,
77
"targets": {
8-
"browsers": "> 1%, IE 11, not op_mini all, not dead"
8+
"browsers": "> 1%, IE 11, not op_mini all, not dead",
9+
"node": "current"
910
},
1011
"useBuiltIns": "usage",
1112
"corejs": 2
1213
}
13-
]
14+
],
15+
"@babel/preset-typescript"
1416
],
15-
"plugins": [
16-
"@babel/plugin-proposal-class-properties"
17-
]
17+
"plugins": ["@babel/plugin-proposal-class-properties"]
1818
}

.editorconfig

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
# http://editorconfig.org
2-
root = true
3-
4-
[*]
5-
charset = utf-8
6-
end_of_line = lf
7-
indent_size = 2
8-
indent_style = space
9-
insert_final_newline = true
10-
max_line_length = 80
11-
trim_trailing_whitespace = true
12-
13-
[*.md]
14-
max_line_length = 0
15-
trim_trailing_whitespace = false
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
end_of_line = lf
7+
indent_size = 2
8+
indent_style = space
9+
insert_final_newline = true
10+
max_line_length = 80
11+
trim_trailing_whitespace = true
12+
13+
[*.md]
14+
max_line_length = 0
15+
trim_trailing_whitespace = false

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/*

.eslintrc.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
commonjs: true,
5+
es2021: true,
6+
node: true,
7+
jest: true,
8+
},
9+
extends: ['eslint:recommended', 'prettier'],
10+
parser: '@typescript-eslint/parser',
11+
parserOptions: {
12+
ecmaVersion: 13,
13+
},
14+
plugins: ['@typescript-eslint', 'prettier'],
15+
rules: {
16+
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
17+
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
18+
'prettier/prettier': 'warn',
19+
},
20+
}

.prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist
2+
*.md
3+
*.xlsx

.prettierrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true
4+
}

README.md

+57-11
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,43 @@ English | [简体中文](https://github.com/chengpeiquan/vite-plugin-banner/blob
1616

1717
Adds a banner to the top of each generated chunk.
1818

19-
## Usage
20-
2119
> ℹ️ **Only support for Vite 2.**
2220
23-
### Install
21+
## Install
2422

25-
Install the package from npm (or yarn).
23+
Install the package from npm (or yarn, or pnpm).
2624

2725
```bash
2826
npm install --save-dev vite-plugin-banner
2927
```
3028

29+
## Options
30+
31+
Since `v0.2.0`, This plugin support a `String` or an `Object` to be the plugin options.
32+
33+
Plugin Options Type|Description|Example
34+
:--|:--|:--
35+
string|The banner content|[Basic usage](#basic-usage)
36+
{ outDir: string; content: string }|content: The comment content of the banner<br>outDir: The output directory from vite|[Optional parameter format](#optional-parameter-format)
37+
38+
## Usage
39+
40+
In most cases, just use the `String` format as a plugin option.
41+
42+
In some special cases, such as in [VitePress](https://vitepress.vuejs.org/), you need to use `Object` format to pass in plugin options, see [Optional parameter format](#optional-parameter-format).
43+
3144
### Basic usage
3245

3346
Add it to `vite.config.ts`
3447

3548
```ts
3649
// vite.config.ts
37-
import Banner from 'vite-plugin-banner'
50+
import banner from 'vite-plugin-banner'
3851
// Other dependencies...
3952

4053
export default defineConfig({
4154
plugins: [
42-
Banner('This is the Banner content.'),
55+
banner('This is the banner content.'),
4356
]
4457
})
4558
```
@@ -49,7 +62,7 @@ When you run `npm run build` on your project, In the `dist` folder(Or the [build
4962
e.g. in `app.b3a7772e.js`:
5063

5164
```js
52-
/* This is the Banner content. */
65+
/* This is the banner content. */
5366
var e=Object.assign;import{M as t,d as a,u as r,c......
5467
```
5568

@@ -60,7 +73,6 @@ Of course, the most ideal banner is related to your package information.
6073
First, You need to update your `package.json` like this, For example, it contains such field content:
6174

6275
```json
63-
// package.json
6476
{
6577
"name": "chengpeiquan.com",
6678
"version": "0.1.0",
@@ -79,7 +91,7 @@ import pkg from './package.json'
7991

8092
export default defineConfig({
8193
plugins: [
82-
Banner(`/**\n * name: ${pkg.name}\n * version: v${pkg.version}\n * description: ${pkg.description}\n * author: ${pkg.author}\n * homepage: ${pkg.homepage}\n */`),
94+
banner(`/**\n * name: ${pkg.name}\n * version: v${pkg.version}\n * description: ${pkg.description}\n * author: ${pkg.author}\n * homepage: ${pkg.homepage}\n */`),
8395
]
8496
})
8597
```
@@ -113,7 +125,7 @@ Such as:
113125
// vite.config.ts
114126
export default defineConfig({
115127
plugins: [
116-
Banner(`
128+
banner(`
117129
██ ██ ███████ ██ ██ ████████ ██ ██ ███████ ██ ██
118130
░██ ░██ ██░░░░░██ ░██ ░██░██░░░░░ ░░██ ██ ██░░░░░██ ░██ ░██
119131
░██ ░██ ██ ░░██░██ ░██░██ ░░████ ██ ░░██░██ ░██
@@ -143,6 +155,40 @@ Run `npm run build`, e.g. in `app.d9a287b8.js`:
143155
var e=Object.assign;import{M as t,d as a,u as r,c......
144156
```
145157

158+
### Optional parameter format
159+
160+
I'm not sure what other scenarios besides VitePress need to use this method to pass in options, so I use VitePress as an example, I hope it can give you a reference
161+
162+
```ts
163+
// docs/.vitepress/config.ts
164+
import { defineConfig } from 'vitepress'
165+
import banner from 'vite-plugin-banner'
166+
import pkg from '../../package.json'
167+
168+
const outDir = '../dist'
169+
170+
export default defineConfig({
171+
// Specify the output directory for packaging
172+
outDir,
173+
174+
// Use Vite plugins
175+
vite: {
176+
plugins: [
177+
// Please remember to use the options in Object format here
178+
banner({
179+
outDir,
180+
content: `/**\n * name: ${pkg.name}\n * version: v${pkg.version}\n * description: ${pkg.description}\n * author: ${pkg.author}\n * homepage: ${pkg.homepage}\n */`,
181+
}),
182+
],
183+
},
184+
// ...
185+
})
186+
```
187+
188+
Why do it?
189+
190+
Because in VitePress, what you get through `viteConfig.build.outDir` is always a `.temp` temporary directory, not the final output directory, so you need to manually specify the output directory to inform the plugin
191+
146192
## License
147193

148-
MIT License © 2021 [chengpeiquan](https://github.com/chengpeiquan)
194+
MIT License © 2021 [chengpeiquan](https://github.com/chengpeiquan)

README.zh-CN.md

+57-11
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,43 @@
1616

1717
为每个 chunk 文件头部添加 banner 注释。
1818

19-
## 用法
20-
2119
> ℹ️ **只支持 Vite 2.**
2220
23-
### 安装
21+
## 安装
2422

25-
从 npm (或者 yarn) 安装:
23+
从 npm (或者 yarn 或者 pnpm) 安装:
2624

2725
```bash
2826
npm install --save-dev vite-plugin-banner
2927
```
3028

29+
## 选项
30+
31+
`v0.2.0` 开始, 这个插件支持使用 `String` 或者 `Object` 格式来作为插件选项。
32+
33+
插件选项类型|作用描述|使用例子
34+
:--|:--|:--
35+
string|横幅注释的内容|[基础用法](#基础用法)
36+
{ outDir: string; content: string }|content: 横幅注释的内容<br>outDir: 来自 Vite 指定的输出目录|[可选参数格式](#可选参数格式)
37+
38+
## 用法
39+
40+
在大多数情况下,只需使用 `String` 格式作为插件选项。
41+
42+
在一些特殊情况下,比如在 [VitePress](https://vitepress.vuejs.org/) 中,需要使用 `Object` 格式来传递插件选项,详见 [可选参数格式](#可选参数格式)
43+
3144
### 基础用法
3245

3346
`vite.config.ts` 添加:
3447

3548
```ts
3649
// vite.config.ts
37-
import Banner from 'vite-plugin-banner'
50+
import banner from 'vite-plugin-banner'
3851
// Other dependencies...
3952

4053
export default defineConfig({
4154
plugins: [
42-
Banner('This is the Banner content.'),
55+
banner('This is the banner content.'),
4356
]
4457
})
4558
```
@@ -49,7 +62,7 @@ export default defineConfig({
4962
例如,在生成的 `app.b3a7772e.js` 里:
5063

5164
```js
52-
/* This is the Banner content. */
65+
/* This is the banner content. */
5366
var e=Object.assign;import{M as t,d as a,u as r,c......
5467
```
5568

@@ -60,7 +73,6 @@ var e=Object.assign;import{M as t,d as a,u as r,c......
6073
首先,你需要更新你的 `package.json` 文件,像这样,包含类似的字段内容:
6174

6275
```json
63-
// package.json
6476
{
6577
"name": "chengpeiquan.com",
6678
"version": "0.1.0",
@@ -79,7 +91,7 @@ import pkg from './package.json'
7991

8092
export default defineConfig({
8193
plugins: [
82-
Banner(`/**\n * name: ${pkg.name}\n * version: v${pkg.version}\n * description: ${pkg.description}\n * author: ${pkg.author}\n * homepage: ${pkg.homepage}\n */`),
94+
banner(`/**\n * name: ${pkg.name}\n * version: v${pkg.version}\n * description: ${pkg.description}\n * author: ${pkg.author}\n * homepage: ${pkg.homepage}\n */`),
8395
]
8496
})
8597
```
@@ -113,7 +125,7 @@ var e=Object.assign;import{M as t,d as a,u as r,c......
113125
// vite.config.ts
114126
export default defineConfig({
115127
plugins: [
116-
Banner(`
128+
banner(`
117129
██ ██ ███████ ██ ██ ████████ ██ ██ ███████ ██ ██
118130
░██ ░██ ██░░░░░██ ░██ ░██░██░░░░░ ░░██ ██ ██░░░░░██ ░██ ░██
119131
░██ ░██ ██ ░░██░██ ░██░██ ░░████ ██ ░░██░██ ░██
@@ -143,6 +155,40 @@ export default defineConfig({
143155
var e=Object.assign;import{M as t,d as a,u as r,c......
144156
```
145157

158+
### 可选参数格式
159+
160+
我不确定除了 VitePress 还有哪些场景需要用到这种方式来传入选项,所以我用 VitePress 来举例,希望能给到你参考。
161+
162+
```ts
163+
// docs/.vitepress/config.ts
164+
import { defineConfig } from 'vitepress'
165+
import banner from 'vite-plugin-banner'
166+
import pkg from '../../package.json'
167+
168+
const outDir = '../dist'
169+
170+
export default defineConfig({
171+
// 指定打包的输出目录
172+
outDir,
173+
174+
// 使用 Vite 插件
175+
vite: {
176+
plugins: [
177+
// 请记住在这里使用 Object 格式的选项
178+
banner({
179+
outDir,
180+
content: `/**\n * name: ${pkg.name}\n * version: v${pkg.version}\n * description: ${pkg.description}\n * author: ${pkg.author}\n * homepage: ${pkg.homepage}\n */`,
181+
}),
182+
],
183+
},
184+
// ...
185+
})
186+
```
187+
188+
为什么要这么做?
189+
190+
因为在 VitePress 里,通过 viteConfig.build.outDir 拿到的永远是一个 `.temp` 的临时目录,不是最终的输出目录,所以你需要手动指定输出目录来告知插件。
191+
146192
## License
147193

148-
MIT License © 2021 [chengpeiquan](https://github.com/chengpeiquan)
194+
MIT License © 2021 [chengpeiquan](https://github.com/chengpeiquan)

dist/checkComment.d.ts

-2
This file was deleted.

dist/libs/getConfig.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import type { PluginOptions, PluginConfig } from '../types';
2+
export default function (options: string | PluginOptions): PluginConfig;

dist/libs/verifyBanner.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default function (content: string): string;

dist/main.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
declare const banner: (comment: string) => any;
2-
export default banner;
1+
import type { PluginOptions } from './types';
2+
export default function (pluginOptions: string | PluginOptions): any;

dist/types/index.d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export interface PluginOptions {
2+
content: string;
3+
outDir?: string;
4+
}
5+
export interface PluginConfig {
6+
content: string;
7+
outDir: string;
8+
}

0 commit comments

Comments
 (0)