Skip to content

Latest commit

 

History

History
51 lines (33 loc) · 1.02 KB

README.md

File metadata and controls

51 lines (33 loc) · 1.02 KB

vite-plugin-force-inline-module

This plugin is tricking Vite into inlining contents of files/imports that match the inlineModules argument. Somehow Vite is not making use of the shouldTransformCachedModules hook of rollup. We trick Vite into busting its own cache, therefore inlining the modules code.

Usage (also see example package)

in vite.config.ts

import { forceInlineModule } from 'vite-plugin-force-inline-module'

export default defineConfig{
  ...
  plugins: [forceInlineModule({ inlineModules: [MODULES_TO_INLINE]})
  ...
}

Example

compare the build output of the example package in dist with plugins used/deactivated in vite.config.ts

Without Plugin:

build1.js / build2.js

import { foobar } from './import_from.js';

console.log("entry_point1", foobar);

With Plugin:

build1.js:

const foobar = "Foobar";

console.log("entry_point1", foobar);

build2.js:

const foobar = "Foobar";

console.log("entry_point2", foobar);