[FEATURE-REQUEST] Offline Build Version of App
See original GitHub issue@antfu thanks for this idea. here some insights and ideas + changes (i have adapted for use withour server port running in vscode, in vscode I think we do not need real time update. Just run it again if you want insights. Same behavior expected since it is similar to coverage of test).
We would need to allow running the UI offline with loading saved report.json from file (including using vscode webview URI’s)
I would open PR, but I do not know how to make a second vite config, to build an additonal version. would be great if we can have it as an addtional script build, like build:app
& build:app-offline
a) we would need another html base struct… https://github.com/windicss/windicss-analysis/blob/main/index.html
// output.html
<!DOCTYPE html>
<html lang="en">
<head>
<script>
window.localStorage.setItem("report", "###REPLACEJSON###")
</script>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Windi Analyser</title>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@300;400;500&display=swap" rel="stylesheet">
<script type="module" crossorigin src="###REPLACESCRIPT###"></script>
<link rel="stylesheet" href="###REPLACESTYLE###">
</head>
<body>
<div id="app"></div>
</body>
</html>
b) we would include additional loader, maybe combine them with if
, or do two differnt functions
https://github.com/windicss/windicss-analysis/blob/3aec1f1ea9432231fe8c53de2e8162cba1088464/src/logic/state.ts#L7-L12
export async function fetchData(refetch = false) {
data.value = await fetch(`/api/report.json${refetch ? '?force=true' : ''}`)
.then(r => r.json())
return data.value
}
export async function loadData() {
data.value = JSON.parse(window.localStorage.getItem("report").toString())
return data.value
}
c) we would need to choose which data to load, somehow (maybe based on some localStorage var) https://github.com/windicss/windicss-analysis/blob/3aec1f1ea9432231fe8c53de2e8162cba1088464/src/main.ts#L20
if (something) {
loadData()
} else {
fetchData()
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (6 by maintainers)
feature mostly implemented for beta
See: https://github.com/windicss/windicss-analysis/commit/35373911e57f99f0b98bf7a4bad787acea6f3a6a
There is no need to have multiple builds for this.
When you serve the HTML to VS Code, you can do a simple transform and inject this script: