-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: smaller page size and fix CSS error in safari and support relat…
…ive path
- Loading branch information
Showing
8 changed files
with
316 additions
and
156 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,66 @@ | ||
let path = require('path'); | ||
let fs = require('fs'); | ||
const {minify} = require('html-minifier-terser'); | ||
let gzipAsync = require('@gfx/zopfli').gzipAsync; | ||
|
||
const SAVE_PATH = '../src'; | ||
|
||
function chunkArray(myArray, chunk_size) { | ||
let index = 0; | ||
let arrayLength = myArray.length; | ||
let tempArray = []; | ||
for (index = 0; index < arrayLength; index += chunk_size) { | ||
let myChunk = myArray.slice(index, index + chunk_size); | ||
tempArray.push(myChunk); | ||
} | ||
return tempArray; | ||
} | ||
|
||
function addLineBreaks(buffer) { | ||
let data = ''; | ||
let chunks = chunkArray(buffer, 30); | ||
chunks.forEach((chunk, index) => { | ||
data += chunk.join(','); | ||
if (index + 1 !== chunks.length) { | ||
data += ',\n'; | ||
} | ||
}); | ||
return data; | ||
} | ||
|
||
(async function(){ | ||
const indexHtml = fs.readFileSync(path.resolve(__dirname, './index.html')).toString(); | ||
const indexHtmlMinify = await minify(indexHtml, { | ||
collapseWhitespace: true, | ||
removeComments: true, | ||
removeAttributeQuotes: true, | ||
removeRedundantAttributes: true, | ||
removeScriptTypeAttributes: true, | ||
removeStyleLinkTypeAttributes: true, | ||
useShortDoctype: true, | ||
minifyCSS: true, | ||
minifyJS: true, | ||
sortAttributes: true, // 不会改变生成的html长度 但会优化压缩后体积 | ||
sortClassName: true, // 不会改变生成的html长度 但会优化压缩后体积 | ||
}); | ||
console.log(`[finalize.js] Minified index.html | Original Size: ${(indexHtml.length / 1024).toFixed(2) }KB | Minified Size: ${(indexHtmlMinify.length / 1024).toFixed(2) }KB`); | ||
|
||
try{ | ||
const GZIPPED_INDEX = await gzipAsync(indexHtmlMinify, { numiterations: 15 }); | ||
|
||
const FILE = | ||
`#ifndef _webserial_webapge_h | ||
#define _webserial_webpage_h | ||
const uint32_t WEBSERIAL_HTML_SIZE = ${GZIPPED_INDEX.length}; | ||
const uint8_t WEBSERIAL_HTML[] PROGMEM = { | ||
${ addLineBreaks(GZIPPED_INDEX) } | ||
}; | ||
#endif | ||
`; | ||
|
||
fs.writeFileSync(path.resolve(__dirname, SAVE_PATH+'/WebSerialWebPage.h'), FILE); | ||
console.log(`[finalize.js] Compressed Bundle into WebSerialWebPage.h header file | Total Size: ${(GZIPPED_INDEX.length / 1024).toFixed(2) }KB`) | ||
}catch(err){ | ||
return console.error(err); | ||
} | ||
})(); |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,9 @@ | ||
{ | ||
"scripts": { | ||
"build": "node finalize.js" | ||
}, | ||
"dependencies": { | ||
"@gfx/zopfli": "^1.0.15" | ||
"@gfx/zopfli": "^1.0.15", | ||
"html-minifier-terser": "^7.1.0" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.