Skip to content

Commit

Permalink
docs: update usage
Browse files Browse the repository at this point in the history
  • Loading branch information
chengpeiquan committed Jan 9, 2022
1 parent a956294 commit 5771923
Show file tree
Hide file tree
Showing 2 changed files with 231 additions and 153 deletions.
42 changes: 37 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ Add it to `vite.config.ts`

```ts
// vite.config.ts
import Banner from 'vite-plugin-banner'
import banner from 'vite-plugin-banner'
// Other dependencies...

export default defineConfig({
plugins: [
Banner('This is the Banner content.'),
banner('This is the banner content.'),
]
})
```
Expand All @@ -62,7 +62,7 @@ When you run `npm run build` on your project, In the `dist` folder(Or the [build
e.g. in `app.b3a7772e.js`:

```js
/* This is the Banner content. */
/* This is the banner content. */
var e=Object.assign;import{M as t,d as a,u as r,c......
```

Expand Down Expand Up @@ -91,7 +91,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 */`),
banner(`/**\n * name: ${pkg.name}\n * version: v${pkg.version}\n * description: ${pkg.description}\n * author: ${pkg.author}\n * homepage: ${pkg.homepage}\n */`),
]
})
```
Expand Down Expand Up @@ -125,7 +125,7 @@ Such as:
// vite.config.ts
export default defineConfig({
plugins: [
Banner(`
banner(`
██ ██ ███████ ██ ██ ████████ ██ ██ ███████ ██ ██
░██ ░██ ██░░░░░██ ░██ ░██░██░░░░░ ░░██ ██ ██░░░░░██ ░██ ░██
░██ ░██ ██ ░░██░██ ░██░██ ░░████ ██ ░░██░██ ░██
Expand Down Expand Up @@ -157,6 +157,38 @@ var e=Object.assign;import{M as t,d as a,u as r,c......

### Optional parameter format

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

```ts
// docs/.vitepress/config.ts
import { defineConfig } from 'vitepress'
import banner from 'vite-plugin-banner'
import pkg from '../../package.json'

const outDir = '../dist'

export default defineConfig({
// Specify the output directory for packaging
outDir,

// Use Vite plugins
vite: {
plugins: [
// Please remember to use the options in Object format here
banner({
outDir,
content: `/**\n * name: ${pkg.name}\n * version: v${pkg.version}\n * description: ${pkg.description}\n * author: ${pkg.author}\n * homepage: ${pkg.homepage}\n */`,
}),
],
},
// ...
})
```

Why do it?

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

## License

MIT License © 2021 [chengpeiquan](https://github.com/chengpeiquan)
Loading

0 comments on commit 5771923

Please sign in to comment.