https://github.com/divriots/vite-plugin-bundled-entry
Vite plugin that generates a bundled entry file.
https://github.com/divriots/vite-plugin-bundled-entry
Last synced: about 1 year ago
JSON representation
Vite plugin that generates a bundled entry file.
- Host: GitHub
- URL: https://github.com/divriots/vite-plugin-bundled-entry
- Owner: divriots
- License: mit
- Created: 2021-12-02T13:32:15.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-01-25T13:53:21.000Z (over 2 years ago)
- Last Synced: 2025-05-04T07:45:58.536Z (about 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 60.5 KB
- Stars: 25
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# vite-plugin-bundled-entry [](https://www.npmjs.com/package/vite-plugin-bundled-entry)
### Purpose
Vite goes to great length *not* to bundle anything (in dev), but there are cases where you've got no choice but to bundle.
Some examples are:
- worker (web/shared/service) which need to run as IIFE and *not* `{type: 'module}` (e.g. using `importScripts`)
- JS entry point which needs to be available dynamically at runtime (e.g. in an iframe)
### Installation
```
npm install --save-dev vite-plugin-bundled-entry
```
### Usage
Add it to vite.config.js
```js
import bundledEntryPlugin from 'vite-plugin-bundled-entry';
export default {
plugins: [bundledEntryPlugin({
id: 'some_virtual_id',
outFile: '/assets/mybundle.[hash].js',
entryPoint: 'src/path/to/entryfile.js',
esbuildOptions: {
// (optional) esbuild options to use for bundling
minify: process.env.NODE_ENV === 'production',
format: 'iife', // default "esm"
},
transform(code) {
// (optional) transform to apply on generated bundle
}
})]
}
```
In your code
```js
import url from 'some_virtual_id?url';
// will be /assets/mybundle.[hash].js (with hash placeholder replaced in build mode)
function createWorker() {
return new Worker(url);
}
```
### License
[MIT](https://opensource.org/licenses/MIT)
Copyright (c) 2021-present,
Riots