|
1 | | -# vite-plugin-banner |
| 1 | +<p align='center'> |
| 2 | + <img src="https://cdn.jsdelivr.net/gh/chengpeiquan/assets-storage/img/2021/02/20210224005014.png" alt="vite-plugin-banner" /> |
| 3 | +</p> |
| 4 | + |
| 5 | +<p align='center'> |
| 6 | + <a href='https://www.npmjs.com/package/vite-plugin-banner'> |
| 7 | + <img src="https://img.shields.io/npm/v/vite-plugin-banner?color=56b7ff&label=npm" /> |
| 8 | + </a> |
| 9 | +</p> |
| 10 | +<br> |
| 11 | +<br> |
| 12 | + |
| 13 | +English | [简体中文](https://github.com/chengpeiquan/vite-plugin-banner/blob/main/README.zh-CN.md) |
| 14 | + |
| 15 | +## Features |
| 16 | + |
| 17 | +Adds a banner to the top of each generated chunk. |
| 18 | + |
| 19 | +## Usage |
| 20 | + |
| 21 | +> ℹ️ **Only support for Vite 2.** |
| 22 | +
|
| 23 | +### Install |
| 24 | + |
| 25 | +Install the package from npm (or yarn). |
| 26 | + |
| 27 | +```bash |
| 28 | +npm install --save-dev vite-plugin-banner |
| 29 | +``` |
| 30 | + |
| 31 | +### Basic usage |
| 32 | + |
| 33 | +Add it to `vite.config.ts` |
| 34 | + |
| 35 | +```ts |
| 36 | +// vite.config.ts |
| 37 | +import Banner from 'vite-plugin-banner' |
| 38 | +// Other dependencies... |
| 39 | + |
| 40 | +export default defineConfig({ |
| 41 | + plugins: [ |
| 42 | + Banner('This is the Banner content.'), |
| 43 | + ] |
| 44 | +}) |
| 45 | +``` |
| 46 | + |
| 47 | +When you run `npm run build` on your project, In the `dist` folder(Or the [build.outDir](https://vitejs.dev/config/#build-outdir) in `vite.config.ts` you configured), Except for `vendor` files, all `js` and `css` files will add a banner to the top. |
| 48 | + |
| 49 | +e.g. in `app.b3a7772e.js`: |
| 50 | + |
| 51 | +```js |
| 52 | +/* This is the Banner content. */ |
| 53 | +var e=Object.assign;import{M as t,d as a,u as r,c...... |
| 54 | +``` |
| 55 | + |
| 56 | +### Advanced usage |
| 57 | + |
| 58 | +Of course, the most ideal banner is related to your package information. |
| 59 | + |
| 60 | +First, You need to update your `package.json` like this, For example, it contains such field content: |
| 61 | + |
| 62 | +```json |
| 63 | +// package.json |
| 64 | +{ |
| 65 | + "name": "chengpeiquan.com", |
| 66 | + "version": "0.1.0", |
| 67 | + "description": "My personal website, technology stack based on Vue.js 3.0, and Vite 2.0, use Server Side Generation.", |
| 68 | + "author": "chengpeiquan", |
| 69 | + "homepage": "https://chengpeiquan.com/" |
| 70 | +} |
| 71 | +``` |
| 72 | + |
| 73 | +Then, import the `package.json` into `vite.config.ts`, update the banner like this: |
| 74 | + |
| 75 | +```ts |
| 76 | +// vite.config.ts |
| 77 | +import pkg from './package.json' |
| 78 | +// Other dependencies... |
| 79 | + |
| 80 | +export default defineConfig({ |
| 81 | + plugins: [ |
| 82 | + Banner(`/**\n * name: ${pkg.name}\n * version: v${pkg.version}\n * description: v${pkg.description}\n * author: ${pkg.author}\n * homepage: ${pkg.homepage}\n */`), |
| 83 | + ] |
| 84 | +}) |
| 85 | +``` |
| 86 | + |
| 87 | +Run `npm run build`, you can see the banner become more detailed. |
| 88 | + |
| 89 | +e.g. in `app.b3a7772e.js`: |
| 90 | + |
| 91 | +```js |
| 92 | +/** |
| 93 | + * name: chengpeiquan.com |
| 94 | + * version: v0.1.0 |
| 95 | + * description: vMy personal website, technology stack based on Vue.js 3.0, and Vite 2.0, use Server Side Generation. |
| 96 | + * author: chengpeiquan |
| 97 | + * homepage: https://chengpeiquan.com/ |
| 98 | + */ |
| 99 | +var e=Object.assign;import{M as t,d as a,u as r,c...... |
| 100 | +``` |
| 101 | + |
| 102 | +### Fun usage |
| 103 | + |
| 104 | +If you want to make some banners that show your personality, you can make some interesting content from some online generators. |
| 105 | + |
| 106 | +Such as: |
| 107 | + |
| 108 | +- [http://www.network-science.de/ascii/](http://www.network-science.de/ascii/) |
| 109 | + |
| 110 | +- [https://www.bootschool.net/ascii](https://www.bootschool.net/ascii) |
| 111 | + |
| 112 | +```ts |
| 113 | +// vite.config.ts |
| 114 | +export default defineConfig({ |
| 115 | + plugins: [ |
| 116 | + Banner(` |
| 117 | + ██ ██ ███████ ██ ██ ████████ ██ ██ ███████ ██ ██ |
| 118 | + ░██ ░██ ██░░░░░██ ░██ ░██░██░░░░░ ░░██ ██ ██░░░░░██ ░██ ░██ |
| 119 | + ░██ ░██ ██ ░░██░██ ░██░██ ░░████ ██ ░░██░██ ░██ |
| 120 | + ░██ ░██ ░██ ░██░░██ ██ ░███████ ░░██ ░██ ░██░██ ░██ |
| 121 | + ░██ ░██ ░██ ░██ ░░██ ██ ░██░░░░ ░██ ░██ ░██░██ ░██ |
| 122 | + ░██ ░██ ░░██ ██ ░░████ ░██ ░██ ░░██ ██ ░██ ░██ |
| 123 | + ░██ ░████████ ░░███████ ░░██ ░████████ ░██ ░░███████ ░░███████ |
| 124 | + ░░ ░░░░░░░░ ░░░░░░░ ░░ ░░░░░░░░ ░░ ░░░░░░░ ░░░░░░░ |
| 125 | + `) |
| 126 | + ] |
| 127 | +}) |
| 128 | +``` |
| 129 | + |
| 130 | +Run `npm run build`, e.g. in `app.d9a287b8.js`: |
| 131 | + |
| 132 | +```js |
| 133 | +/* |
| 134 | + ██ ██ ███████ ██ ██ ████████ ██ ██ ███████ ██ ██ |
| 135 | + ░██ ░██ ██░░░░░██ ░██ ░██░██░░░░░ ░░██ ██ ██░░░░░██ ░██ ░██ |
| 136 | + ░██ ░██ ██ ░░██░██ ░██░██ ░░████ ██ ░░██░██ ░██ |
| 137 | + ░██ ░██ ░██ ░██░░██ ██ ░███████ ░░██ ░██ ░██░██ ░██ |
| 138 | + ░██ ░██ ░██ ░██ ░░██ ██ ░██░░░░ ░██ ░██ ░██░██ ░██ |
| 139 | + ░██ ░██ ░░██ ██ ░░████ ░██ ░██ ░░██ ██ ░██ ░██ |
| 140 | + ░██ ░████████ ░░███████ ░░██ ░████████ ░██ ░░███████ ░░███████ |
| 141 | + ░░ ░░░░░░░░ ░░░░░░░ ░░ ░░░░░░░░ ░░ ░░░░░░░ ░░░░░░░ |
| 142 | + */ |
| 143 | +var e=Object.assign;import{M as t,d as a,u as r,c...... |
| 144 | +``` |
| 145 | + |
| 146 | +## License |
| 147 | + |
| 148 | +MIT License © 2021 [chengpeiquan](https://github.com/chengpeiquan) |
0 commit comments