-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: 📝 add instructions to the README
- Loading branch information
1 parent
73373c3
commit 17c8033
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,47 @@ | ||
# vite-plugin-add-scripts | ||
A Vite plugin to add custom scripts to the index.html file | ||
|
||
## Installation | ||
``` | ||
npm install vite-plugin-add-scripts | ||
``` | ||
|
||
## Usage | ||
Add your plugin to the `plugins` array. You can also specify when the plugin | ||
should be used with the `apply` option. | ||
|
||
```js | ||
// vite.config.js | ||
import ViteAddScripts from 'vite-plugin-add-scripts' | ||
|
||
export default { | ||
plugins: [ | ||
{ | ||
...ViteAddScripts([ | ||
{ | ||
position: 'head', | ||
content: '<script>window.foo = {}</script>' | ||
} | ||
]), | ||
apply: 'build', | ||
} | ||
] | ||
} | ||
``` | ||
|
||
## Options | ||
You can use the `position` option to add the script to either the head or the | ||
body section of the index.html file | ||
|
||
The `content` option is the actual content that gets written to the file. | ||
Normally it would be a stringified version of the script tags and their | ||
contents. | ||
|
||
```js | ||
...ViteAddScripts([ | ||
{ | ||
position: 'body', // or 'head' | ||
content: '<sciprt>window.foo = {}</script>' | ||
} | ||
]), | ||
``` |