0.5.1 • Published 4 months ago

vite-plugin-bundled-entry v0.5.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

vite-plugin-bundled-entry npm

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

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

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

Copyright (c) 2021-present, Riots

0.5.1

4 months ago

0.5.0

5 months ago

0.4.0

2 years ago

0.3.0

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.8

2 years ago

0.3.1

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago