Skip to content

HTML Inline Script Plugin

A plugin for staticbolt that inlines external scripts into the HTML at build time. It works with local files and remote URLs.

Installation

The plugin ships as part of @staticbolt/core. You do not need to install anything else.

Usage

In your .staticbolt.ts configuration file:

import { defineConfig } from "@staticbolt/core";
import { htmlInlineScriptPlugin } from "@staticbolt/core/plugins";
export default defineConfig({
plugins: [htmlInlineScriptPlugin()],
});
Caution

When a module script that has exports is inlined, nothing can reference those exports anymore.

Inlining a script

Add the inline attribute to any <script src="..."> tag. At build time the plugin reads the file, injects its content inline, and removes the src attribute.

<script src="./app.js" inline></script>

Inlining only happens in production builds. During development the plugin strips the inline attribute and the script keeps loading as an external file.

Using a remote URL

The src attribute can also point to a remote URL. The plugin downloads the file at build time and inlines its content.

<script src="https://example.com/vendor.js" inline></script>

Plugin Options

inlineAttribute

  • Type: string
  • Default: "inline"

The attribute name that marks a script tag for inlining.

htmlInlineScriptPlugin({
inlineAttribute: "embed",
});