Replies: 1 comment 1 reply
-
I'm not aware of any existing ways to do this. The new file api coming in #408 (hopefully will land this week or next) will be adding a full file transformation pipeline that would make it easy for a plugin to implement something like this. However, I'm not sure mangling/minifying/merging would actually make a significant difference in the final file size. The .zip and squashfs processes are extremely efficient, especially on text-based files. I would suggest you do do some tests to see what the real-world zip size reduction would be for your app. As a quick example, I took the View mangle.tsimport * as fastGlob from 'fast-glob';
import * as fsExtra from 'fs-extra';
const files = fastGlob.sync('**/*', {
cwd: 'src',
absolute: false
});
for (const file of files) {
let contents = fsExtra.readFileSync(`src/${file}`).toString()
contents = contents
//remove comments
.replace(/'.*(?=\n|$)/g, '')
//condense consecutive newlines to a single newline
.replace(/\r?\n+/g, '\n')
//mangle all words
.replace(/(?<!")(\w+)/g, function (match, word) {
//skip the known brightscript keywords
if ([
'function', 'sub', 'if', 'then', 'else', 'end', 'while', 'true', 'false', 'continue', 'exit', 'not', 'as', 'return', 'each',
'invalid', 'integer', 'longinteger', 'dynamic', 'boolean', 'float', 'object', 'string',
'createchild', 'createobject', 'update', 'type',
].includes(word.toLowerCase())) {
return word;
} else {
return word[0];
}
})
//condense whitespace
.replace(/( |\t)+/g, ' ')
//trim every line
.replace(/^.*$/gm, function (match) {
return match.trim();
});
fsExtra.outputFileSync(`./dest/${file}`, contents);
} Then, here's the sizes of each. The original code zipped is 965KB, and the mangled zip is 583KB zipped. |
Beta Was this translation helpful? Give feedback.
-
Is there some way to ask
bsc
to generate minified .brs files? like putting every source/*.bs file in a single .brs, do some name mangling, etc...I have this requirement to fit my library in a very small space...
Beta Was this translation helpful? Give feedback.
All reactions