Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@chialab/esbuild-plugin-html

Package Overview
Dependencies
Maintainers
2
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chialab/esbuild-plugin-html - npm Package Compare versions

Comparing version 0.6.0 to 0.7.0

15

lib/collectAssets.js

@@ -9,5 +9,6 @@ import path from 'path';

* @param {string} outdir The output dir.
* @param {import('esbuild').BuildOptions} options Build options.
* @return {import('./index').Entrypoint[]} A list of entrypoints.
*/
export function collectAssets(dom, base, outdir) {
export function collectAssets(dom, base, outdir, options) {
return [

@@ -24,5 +25,5 @@ ...dom

],
entryNames: 'assets/[name]-[hash]',
chunkNames: 'assets/[name]-[hash]',
assetNames: 'assets/[name]-[hash]',
entryNames: `assets/${options.entryNames || '[name]'}`,
chunkNames: `assets/${options.chunkNames || '[name]'}`,
assetNames: `assets/${options.assetNames || '[name]'}`,
},

@@ -46,5 +47,5 @@ /**

],
entryNames: 'assets/[name]-[hash]',
chunkNames: 'assets/[name]-[hash]',
assetNames: 'assets/[name]-[hash]',
entryNames: `assets/${options.entryNames || '[name]'}`,
chunkNames: `assets/${options.chunkNames || '[name]'}`,
assetNames: `assets/${options.assetNames || '[name]'}`,
},

@@ -51,0 +52,0 @@ /**

@@ -9,5 +9,6 @@ import path from 'path';

* @param {string} outdir The output dir.
* @param {import('esbuild').BuildOptions} options Build options.
* @return {import('./index').Entrypoint[]} A list of entrypoints.
*/
export function collectScripts(dom, base, outdir, targets = { scriptsTarget: 'es6', modulesTarget: 'es2020' }) {
export function collectScripts(dom, base, outdir, targets = { scriptsTarget: 'es6', modulesTarget: 'es2020' }, options) {
return [

@@ -24,5 +25,5 @@ ...dom.find('script[src][type="module"]')

format: /** @type {import('esbuild').Format} */ ('esm'),
entryNames: 'esm/[name]-[hash]',
chunkNames: 'esm/[name]-[hash]',
assetNames: 'esm/assets/[name]-[hash]',
entryNames: `esm/${options.entryNames || '[name]'}`,
chunkNames: `esm/${options.chunkNames || '[name]'}`,
assetNames: `esm/assets/${options.assetNames || '[name]'}`,
},

@@ -54,5 +55,5 @@ /**

format: /** @type {import('esbuild').Format} */ ('esm'),
entryNames: 'esm/[name]-[hash]',
chunkNames: 'esm/[name]-[hash]',
assetNames: 'esm/assets/[name]-[hash]',
entryNames: `esm/${options.entryNames || '[name]'}`,
chunkNames: `esm/${options.chunkNames || '[name]'}`,
assetNames: `esm/assets/${options.assetNames || '[name]'}`,
},

@@ -77,5 +78,5 @@ /**

format: /** @type {import('esbuild').Format} */ ('iife'),
entryNames: 'iife/[name]-[hash]',
chunkNames: 'iife/[name]-[hash]',
assetNames: 'iife/assets/[name]-[hash]',
entryNames: `iife/${options.entryNames || '[name]'}`,
chunkNames: `iife/${options.chunkNames || '[name]'}`,
assetNames: `iife/assets/${options.assetNames || '[name]'}`,
splitting: false,

@@ -109,5 +110,5 @@ },

globalName: undefined,
entryNames: 'iife/[name]-[hash]',
chunkNames: 'iife/[name]-[hash]',
assetNames: 'iife/assets/[name]-[hash]',
entryNames: `iife/${options.entryNames || '[name]'}`,
chunkNames: `iife/${options.chunkNames || '[name]'}`,
assetNames: `iife/assets/${options.assetNames || '[name]'}`,
splitting: false,

@@ -114,0 +115,0 @@ },

@@ -9,5 +9,6 @@ import path from 'path';

* @param {string} outdir The output dir.
* @param {import('esbuild').BuildOptions} options Build options.
* @return {import('./index').Entrypoint[]} A list of entrypoints.
*/
export function collectStyles(dom, base, outdir) {
export function collectStyles(dom, base, outdir, options) {
return [

@@ -24,5 +25,5 @@ ...dom

],
entryNames: 'css/[name]-[hash]',
chunkNames: 'css/[name]-[hash]',
assetNames: 'css/assets/[name]-[hash]',
entryNames: `css/${options.entryNames || '[name]'}`,
chunkNames: `css/${options.chunkNames || '[name]'}`,
assetNames: `css/assets/${options.assetNames || '[name]'}`,
},

@@ -51,5 +52,5 @@ /**

},
entryNames: 'css/[name]-[hash]',
chunkNames: 'css/[name]-[hash]',
assetNames: 'css/assets/[name]-[hash]',
entryNames: `css/${options.entryNames || '[name]'}`,
chunkNames: `css/${options.chunkNames || '[name]'}`,
assetNames: `css/assets/${options.assetNames || '[name]'}`,
},

@@ -56,0 +57,0 @@ /**

@@ -31,35 +31,35 @@ import path from 'path';

setup(build) {
let options = build.initialOptions;
const options = build.initialOptions;
build.onLoad({ filter: /\.html$/ }, async ({ path: filePath }) => {
let contents = await readFile(filePath, 'utf-8');
let basePath = path.dirname(filePath);
let outdir = /** @type {string} */ (options.outdir || (options.outfile && path.dirname(options.outfile)));
let dom = $.load(contents);
let root = dom.root();
const contents = await readFile(filePath, 'utf-8');
const basePath = path.dirname(filePath);
const outdir = /** @type {string} */ (options.outdir || (options.outfile && path.dirname(options.outfile)));
const dom = $.load(contents);
const root = dom.root();
let entrypoints = /** @type {Entrypoint[]} */ ([
const entrypoints = /** @type {Entrypoint[]} */ ([
...collectIcons(root, basePath, outdir),
...collectWebManifest(root, basePath, outdir),
...collectStyles(root, basePath, outdir),
...collectScripts(root, basePath, outdir, { scriptsTarget, modulesTarget }),
...collectAssets(root, basePath, outdir),
...collectStyles(root, basePath, outdir, options),
...collectScripts(root, basePath, outdir, { scriptsTarget, modulesTarget }, options),
...collectAssets(root, basePath, outdir, options),
]);
for (let i = 0; i < entrypoints.length; i++) {
let entrypoint = entrypoints[i];
const entrypoint = entrypoints[i];
/** @type {string[]} */
const outputFiles = [];
/** @type {string} */
let outputFile;
/** @type {string[]} */
let outputFiles = [];
if (entrypoint.loader === 'file') {
let files = /** @type {string[]|undefined}} */ (entrypoint.options.entryPoints);
let file = files && files[0];
const files = /** @type {string[]|undefined}} */ (entrypoint.options.entryPoints);
const file = files && files[0];
if (!file) {
continue;
}
let ext = path.extname(file);
let basename = path.basename(file, ext);
let buffer = await readFile(file);
let assetNames = entrypoint.options.assetNames || options.assetNames || '[name]';
const ext = path.extname(file);
const basename = path.basename(file, ext);
const buffer = await readFile(file);
const assetNames = entrypoint.options.assetNames || options.assetNames || '[name]';
let computedName = assetNames

@@ -82,3 +82,3 @@ .replace('[name]', basename)

/** @type {import('esbuild').BuildOptions} */
let config = {
const config = {
...options,

@@ -91,3 +91,3 @@ outfile: undefined,

};
let result = await esbuild.build(config);
const result = await esbuild.build(config);
if (!result.metafile) {

@@ -97,5 +97,5 @@ continue;

let inputFiles = /** @type {string[]} */ (entrypoint.options.entryPoints || []);
let outputs = result.metafile.outputs;
let outputFiles = Object.keys(outputs);
const inputFiles = /** @type {string[]} */ (entrypoint.options.entryPoints || []);
const outputs = result.metafile.outputs;
const outputFiles = Object.keys(outputs);
outputFile = outputFiles

@@ -102,0 +102,0 @@ .filter((output) => !output.endsWith('.map'))

{
"name": "@chialab/esbuild-plugin-html",
"type": "module",
"version": "0.6.0",
"version": "0.7.0",
"description": "A HTML loader plugin for esbuild.",

@@ -44,3 +44,3 @@ "main": "lib/index.js",

},
"gitHead": "3b80a58919d1c42654d5231c9a18049273d3dedf"
"gitHead": "6f48a0ef65d8ecb1266196c08db63a19a1e44712"
}

@@ -6,4 +6,5 @@ /**

* @param {string} outdir The output dir.
* @param {import('esbuild').BuildOptions} options Build options.
* @return {import('./index').Entrypoint[]} A list of entrypoints.
*/
export function collectAssets(dom: import('./esm-cheerio').Document, base: string, outdir: string): import('./index').Entrypoint[];
export function collectAssets(dom: import('./esm-cheerio').Document, base: string, outdir: string, options: import('esbuild').BuildOptions): import('./index').Entrypoint[];

@@ -6,7 +6,8 @@ /**

* @param {string} outdir The output dir.
* @param {import('esbuild').BuildOptions} options Build options.
* @return {import('./index').Entrypoint[]} A list of entrypoints.
*/
export function collectScripts(dom: import('./esm-cheerio').Document, base: string, outdir: string, targets?: {
export function collectScripts(dom: import('./esm-cheerio').Document, base: string, outdir: string, targets: {
scriptsTarget: string;
modulesTarget: string;
}): import('./index').Entrypoint[];
} | undefined, options: import('esbuild').BuildOptions): import('./index').Entrypoint[];

@@ -6,4 +6,5 @@ /**

* @param {string} outdir The output dir.
* @param {import('esbuild').BuildOptions} options Build options.
* @return {import('./index').Entrypoint[]} A list of entrypoints.
*/
export function collectStyles(dom: import('./esm-cheerio').Document, base: string, outdir: string): import('./index').Entrypoint[];
export function collectStyles(dom: import('./esm-cheerio').Document, base: string, outdir: string, options: import('esbuild').BuildOptions): import('./index').Entrypoint[];
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc