Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎉 init #2436

Merged
merged 1 commit into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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