From ea72cc244da8e94f0eb56f5d7f197fea694bcbe0 Mon Sep 17 00:00:00 2001 From: Lapo Luchini Date: Tue, 7 May 2024 07:38:22 +0000 Subject: [PATCH] Improve single-file mode. --- README.md | 2 +- vite.config.js | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0882426..218756f 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ document.body.innerText = ASN1.decode(Hex.decode('06032B6570')).content(); Local usage -------------------- -Since unfortunately ESM modules are not working on `file:` protocol due to [CORS issues](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules#other_differences_between_modules_and_standard_scripts), there is a bundled [single-file version working locally](https://asn1js.eu/index-local.html). It doesn't work online (due to [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) restrictions about inline content) but can be saved locally and opened in a browser. (known bug: dark mode is currently broken in this mode) +Since unfortunately ESM modules are not working on `file:` protocol due to [CORS issues](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules#other_differences_between_modules_and_standard_scripts), there is a bundled [single-file version working locally](https://asn1js.eu/index-local.html). It doesn't work online (due to [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) restrictions about inline content) but can be saved locally and opened in a browser. ([known bug](https://github.com/lapo-luchini/asn1js/issues/89): dark mode is currently broken in this mode) ISC license ----------- diff --git a/vite.config.js b/vite.config.js index 3555525..6fc9a82 100644 --- a/vite.config.js +++ b/vite.config.js @@ -6,18 +6,26 @@ import { DomUtils } from 'htmlparser2'; const removeNodes = [ 'theme-select', 'rowExamples' ]; +const preventSVGEmit = () => { + return { + generateBundle(opts, bundle) { + for (const key in bundle) + if (key.endsWith('.svg')) + delete bundle[key]; + }, + }; +}; + export default defineConfig({ plugins: [ + preventSVGEmit(), pluginDom({ applyOnMode: true, // all modes handler: node => { if (removeNodes.includes(node.attribs.id)) DomUtils.removeElement(node); - else if (node.name == 'link' && node.attribs.rel == 'icon') { - //node.attribs.href = 'data:image/svg+xml,' + encodeURI(fs.readFileSync('favicon.svg', 'ascii').replace(/^([^<]+|<[^s]|