npm install [-g|--save] esbuild-meta-into-html-script-src
then use on commandline (npx esbuild-meta-into-html-script-src ...
) or in scripts
of package.json
to automate
esbuild-meta-into-html-script-src metaJsonPath srcHtmlPath desHtmlPath [srcPrefix [desPrefix]]
metaJsonPath
: meta json file path generated by esbuild: https://esbuild.github.io/api/#metafilesrcHtmlPath
: html template file pathdesHtmlPath
: result html path will be written to
srcPrefix
and desPrefix
: prefix to remove in meta json mapping, for example, entering srcPrefix: 'src/', desPrefix: 'dist/'
will make:
'src/web.js': 'dist/web-NPBBEE7I.js'
become:
'web.js': 'web-NPBBEE7I.js'
esbuild-meta-into-html-script-src meta.json src/index.html dist/index.html src/ dist/
window.ENTRY_POINTS_MAPPING = typeof window !== 'undefined' ? JSON.parse(
document.head.querySelector('meta[name=entry-points-mapping]')?.content || '{}'
) : {}