Skip to content

Commit

Permalink
fix: implement suggestions
Browse files Browse the repository at this point in the history
Co-authored-by: Eric Fennis <[email protected]>
  • Loading branch information
jguddas and ericfennis committed Aug 17, 2023
1 parent ed9db67 commit dbb2cf1
Show file tree
Hide file tree
Showing 6 changed files with 415 additions and 73 deletions.
7 changes: 3 additions & 4 deletions docs/.vitepress/api/gh-icon/dpi/[...data].get.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { eventHandler, setResponseHeader, defaultContentType } from 'h3';
import { Resvg, initWasm } from '@resvg/resvg-wasm';
import wasm from './loadWasm';

const initialization = fetch('https://unpkg.com/@resvg/resvg-wasm/index_bg.wasm').then((res) =>
initWasm(res)
);
var initializedResvg = initWasm(wasm);

export default eventHandler(async (event) => {
const { params = {} } = event.context;
await initialization;
await initializedResvg;

const imageSize = 96;
const [iconSizeString, svgData] = params.data.split('/');
Expand Down
15 changes: 15 additions & 0 deletions docs/.vitepress/api/gh-icon/dpi/loadWasm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import fs from 'fs';
import module from 'node:module';
/* WASM_IMPORT */

let wasm;

if (process.env.NODE_ENV === 'development') {
const require = module.createRequire(import.meta.url);

wasm = fs.readFileSync(require.resolve('@resvg/resvg-wasm/index_bg.wasm'));
} else {
wasm = resvg_wasm;
}

export default wasm;
14 changes: 11 additions & 3 deletions docs/.vitepress/vue-shim.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
declare module "*.vue" {
import Vue from "vue";
declare module '*.vue' {
import Vue from 'vue';
export default Vue;
}

declare module "*.data.ts" {
declare module '*.data.ts' {
const data: any;

export { data };
}

declare module '*.wasm' {}

declare const resvg_wasm: RequestInfo | URL | Response | BufferSource | WebAssembly.Module;

declare module 'node:module' {
function createRequire(filename: string): NodeRequire;
}
33 changes: 24 additions & 9 deletions docs/nitro.config.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
import { defineNitroConfig } from "nitropack";
import copy from 'rollup-plugin-copy';
import replace from '@rollup/plugin-replace';

export default defineNitroConfig({
preset: 'vercel-edge',
srcDir: '.vitepress',
routeRules: {
'/api/**': { cors: false },
},
rollupConfig: {
external: ['@resvg/resvg-wasm/index_bg.wasm', './index_bg.wasm?module'],
plugins: [
copy({
targets: [
{
src: './node_modules/@resvg/resvg-wasm/index_bg.wasm',
dest: './.vercel/output/functions/__nitro.func',
},
],
}),
replace({
include: ['./**/*.ts'],
'/* WASM_IMPORT */': 'import resvg_wasm from "./index_bg.wasm?module";',
delimiters: ['', ''],
preventAssignment: false,
}),
],
},
esbuild: {
options: {
include: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx', '**/*.json'],
loaders: {
'.js': 'js',
'.jsx': 'jsx',
'.ts': 'ts',
'.tsx': 'tsx',
}
jsxFactory: 'React.createElement',
jsxFragment: 'React.Fragment',
},
},
})
});
6 changes: 4 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
"author": "Eric Fennis",
"license": "ISC",
"devDependencies": {
"h3": "^1.7.1",
"nitropack": "^2.5.2",
"@rollup/plugin-replace": "^5.0.2",
"h3": "^1.8.0",
"nitropack": "npm:nitropack-edge@latest",
"node-fetch": "2",
"rollup-plugin-copy": "^3.4.0",
"vitepress": "1.0.0-rc.4"
},
"dependencies": {
Expand Down
Loading

0 comments on commit dbb2cf1

Please sign in to comment.