Skip to content

Commit

Permalink
🎉 (#2436)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuitos authored Mar 13, 2023
1 parent 229c1e0 commit a4007c8
Show file tree
Hide file tree
Showing 55 changed files with 6,638 additions and 8,365 deletions.
15 changes: 0 additions & 15 deletions now.json

This file was deleted.

6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@
"ts-jest": "^25.2.1",
"umi-plugin-hire": "^1.0.3"
},
"resolutions": {
"@types/react": "^17.x",
"@types/history": "^4.x"
},
"repository": {
"type": "git",
"url": "git+https://github.com/kuitos/qiankun.git"
Expand Down Expand Up @@ -83,5 +79,5 @@
"/dist/"
]
},
"packageManager": "pnpm@6.23.0"
"packageManager": "pnpm@7.3.0"
}
20 changes: 20 additions & 0 deletions packages/loader/.fatherrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export default {
target: 'browser',
esm: 'babel',
cjs: 'babel',
umd: {
minFile: true,
sourcemap: true,
},
runtimeHelpers: true,
extraBabelPlugins: [
[
'babel-plugin-import',
{
libraryName: 'lodash',
libraryDirectory: '',
camel2DashComponentName: false,
},
],
],
};
2 changes: 2 additions & 0 deletions packages/loader/benchmarks/parser/html.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/loader/benchmarks/parser/huge-html/huge-html.js

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions packages/loader/benchmarks/parser/huge-html/import-html-entry.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>import html entry for huge html</title>
</head>
<body>

<script type="module">
import * as bench from '/bench.js';
import processTpl from 'import-html-entry/esm/process-tpl.js';
import { hugeHtmlContent } from './huge-html.js';

bench.start();
processTpl(hugeHtmlContent, location.href);
bench.stop();
</script>
</body>
</html>
19 changes: 19 additions & 0 deletions packages/loader/benchmarks/parser/huge-html/parser.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>parser for huge html</title>
</head>
<body>

<script type="module">
import * as bench from '/bench.js';
import { parseHTML } from '../../../es/parser.js';
import { hugeHtmlContent } from './huge-html.js';

bench.start();
parseHTML(hugeHtmlContent, location.href);
bench.stop();
</script>
</body>
</html>
19 changes: 19 additions & 0 deletions packages/loader/benchmarks/parser/import-html-entry.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>import html entry for normal html</title>
</head>
<body>

<script type="module">
import * as bench from '/bench.js';
import processTpl from 'import-html-entry/esm/process-tpl.js';
import { htmlContent } from './html.js';

bench.start();
processTpl(htmlContent, location.href);
bench.stop();
</script>
</body>
</html>
19 changes: 19 additions & 0 deletions packages/loader/benchmarks/parser/parser.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>parser for normal html</title>
</head>

<body>
<script type="module">
import * as bench from '/bench.js';
import { parseHTML } from '../../es/parser.js';
import { htmlContent } from './html.js';

bench.start();
parseHTML(htmlContent, location.href);
bench.stop();
</script>
</body>
</html>
24 changes: 24 additions & 0 deletions packages/loader/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@qiankunjs/loader",
"version": "0.0.1",
"description": "",
"main": "./lib/index.ts",
"module": "./es/index.js",
"scripts": {
"build": "father-build",
"test": "cross-env NODE_ENV=test jest",
"bench": "npm run build && tachometer ./benchmarks/parser/import-html-entry.html ./benchmarks/parser/parser.html ./benchmarks/parser/huge-html/import-html-entry.html ./benchmarks/parser/huge-html/parser.html --timeout=1"
},
"author": "",
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.10.5"
},
"devDependencies": {
"babel-plugin-import": "^1.12.1",
"father-build": "^1.7.0",
"import-html-entry": "^1.12.0",
"tachometer": "^0.5.10",
"typescript": "^4.1.2"
}
}
33 changes: 33 additions & 0 deletions packages/loader/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import WritableDOMStream from './writable-dom';

type HTMLEntry = string;
// type ConfigEntry = { html: string; scripts: [], styles: [] };

type Entry = HTMLEntry;

// type EntryInstance<K> = {
// htmlDocument: Document;
// prefetch: () => Promise<void>;
// execute: (executor?: Promise<K>) => Promise<K>;
// };
//
type ImportOpts = {
fetch?: typeof window.fetch;
decoder?: (chunk: string) => string;
assetsTransformer?: (node: Node) => Node;
};

/**
* @param entry
* @param target
* @param opts
* @todo Compatible with browsers that do not support WritableStream/TransformStream
*/
export async function importEntry(entry: Entry, target: HTMLElement, opts?: ImportOpts): Promise<void> {
const { fetch = window.fetch, assetsTransformer } = opts || {};
const res = await fetch(entry);

if (res.body) {
await res.body.pipeThrough(new TextDecoderStream()).pipeTo(new WritableDOMStream(target, null, assetsTransformer));
}
}
23 changes: 23 additions & 0 deletions packages/loader/src/parser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
type NormalizedEntry = {
stylesheets: NodeListOf<HTMLStyleElement>;
scripts: NodeListOf<HTMLScriptElement>;
};

function getDocResources(container: Document) {
const links = container.querySelectorAll<HTMLLinkElement>('link[rel=stylesheet][href]:not([href=""])');
const scripts = container.querySelectorAll<HTMLScriptElement>('script[src]:not([src=""])');

return {
scripts,
stylesheets: links,
};
}

export function parseHTML(htmlContent: string): NormalizedEntry {
const domParser = new DOMParser();
const container = domParser.parseFromString(htmlContent, 'text/html');

const resources = getDocResources(container);

return resources;
}
1 change: 1 addition & 0 deletions packages/loader/src/writable-dom/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Fork from https://github.com/marko-js/writable-dom
Loading

0 comments on commit a4007c8

Please sign in to comment.