-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
55 changed files
with
6,638 additions
and
8,365 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
], | ||
], | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
packages/loader/benchmarks/parser/huge-html/import-html-entry.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Fork from https://github.com/marko-js/writable-dom |
Oops, something went wrong.