Inline raw TypeScript code as a string.
Add ?raw&inline
(or ?inline&raw
) import url suffix support for Vite.
npm i vite-plugin-inline
// vite.config.ts
import { defineConfig } from 'vite';
import Inline from 'vite-plugin-inline';
export default defineConfig({
plugins: [
Inline()
]
});
TypeScript support:
// env.d.ts
/// <reference path="vite-plugin-inline/client" />
For example, you want to import the raw content of inline.ts
which has been transpiled to JavaScript.
// inline.ts
const hello: string = 'hello'
// main.ts
import code from './inline.ts?raw&inline'
console.log(code) // Print: "const hello = 'hello'"
MIT License © 2025 XLor