esbuild-plugin-inject-preload
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

esbuild-plugin-inject-preload

npm license

Injects preload links to html template.

Usage

import { BuildOptions } from 'esbuild';
import { pluginInjectPreload } from 'esbuild-plugin-inject-preload';

const esbuildConfig: BuildOptions = {
  assetNames: '[ext]/[name]' | '[name]', // optional, this plugin supports nested folders
  outdir: path.resolve('build'), // required
  metafile: true, // required
  plugins: [
    pluginInjectPreload({ 
      ext: '.woff',
      linkType: 'font',
      templatePath: path.resolve('build/template.html'),
      replaceString: '<!-- FONT_PRELOAD -->',
    }),
  ],
};

You should place some string into you html like <!-- FONT_PRELOAD --> in the example. So, the output html file will contain links to all files with a certain extension, like:

<link as="font" crossorigin="anonymous" href="/woff/Roboto-Regular.woff" rel="preload">
<link as="font" crossorigin="anonymous" href="/woff/Roboto-Medium.woff" rel="preload">

/esbuild-plugin-inject-preload/

    Package Sidebar

    Install

    npm i esbuild-plugin-inject-preload

    Weekly Downloads

    0

    Version

    0.0.6

    License

    MIT

    Unpacked Size

    5.38 kB

    Total Files

    9

    Last publish

    Collaborators

    • dkazakov8