https://github.com/yue1123/vite-plugin-data-url
Extend vite import query to add data-url import. You can talk about importing the data-url encoding of a resource directly.
https://github.com/yue1123/vite-plugin-data-url
base64 data-url image import import-data query vite vite-plugin
Last synced: 3 months ago
JSON representation
Extend vite import query to add data-url import. You can talk about importing the data-url encoding of a resource directly.
- Host: GitHub
- URL: https://github.com/yue1123/vite-plugin-data-url
- Owner: yue1123
- License: mit
- Created: 2023-05-08T18:08:58.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-04-25T16:32:30.000Z (over 1 year ago)
- Last Synced: 2024-06-22T11:21:45.506Z (over 1 year ago)
- Topics: base64, data-url, image, import, import-data, query, vite, vite-plugin
- Language: TypeScript
- Homepage:
- Size: 70.3 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# vite-plugin-data-url



Add support for data-url query import, you can directly import the data-url address of the image.
## 📦 Install
```shell
npm i vite-plugin-data-url -D
# yarn
yarn add vite-plugin-data-url -D
# pnpm
pnpm add vite-plugin-data-url -D
```
## 🦄 Usage
Add envParse plugin to vite.config.js / vite.config.ts and configure it:
```ts
// vite.config.js / vite.config.ts
import { dataUrl } from 'vite-plugin-data-url'
export default {
plugins: [dataUrl()]
}
```
## Typescript
Add types for `?data-url`
```json
"complierOptions":{
// ...
"types": ["vite-plugin-data-url/types"]
// ...
}
```
## API
### Base64ImportOptions
| Property Name | Type | Description | Default Value |
| ------------- | --------- | -------------------------------------------------------------------------------------------------------------------------- | ------------- |
| sizeWarning | `boolean` | Whether to disable the warning when specified files exceed the set size limit. | `true` |
| limit | `number` | The maximum file size (in KB) for converting to base64. If exceeded, a warning will be given and the file will be ignored. | `10 * 1024` |
## License
[MIT licenses](https://opensource.org/licenses/MIT)