A Babel codemod that acts as a build / compile time optimizer for Lasso JS. Gives Lasso JS some extra arms.
A Babel CodeMod plugin that acts as a build / compile time optimizer for Lasso JS. Gives Lasso JS some extra arms.
$_mod.def("/marko$4.17.3/components/runtime", function (require, exports, module, __filename, __dirname) {
const f_55 = require('/marko$4.17.3/components/index-browser.marko');
exports.a = 45;
exports.func = () => {};
module.exports = () => {
};
});
$_mod_gh_fe.remap("/marko$4.17.3/components", "/marko$4.17.3/components-browser.marko");
$_mod_gh_fe.installed("globalheaderfrontend$25.1.0", "marko", "4.17.3");
$_mod_gh_fe.remap("/marko$4.17.3/src/runtime/components/index", "/marko$4.17.3/src/runtime/components/index-browser");
$_mod.def("/marko$4.17.3/components/runtime", function (require, exports, module, __filename, __dirname) {
// code here
});
$_mod.run("/marko$4.17.3/components/runtime");
$_mod_gh_fe.remap("/marko$4.17.3/components", "/marko$4.17.3/components-browser.marko");
$_mod_gh_fe.installed("globalheaderfrontend$25.1.0", "marko", "4.17.3");
$_mod_gh_fe.main("/process$4.17.3", "src/runtime/components/index-browser");
to
function __marko_4_17_3__components__runtime(require, exports, module, __filename, __dirname) {
/* __marko_4_17_3__components_index_browser__marko is already available in toplevel scope */
const f_55 = require(__marko_4_17_3__components_index_browser__marko);
exports.a = 45;
exports.func = () => {};
module.exports = () => {
};
}
run(__marko_4_17_3__components__runtime);
.remap
, .installed
, .main
, .run
, .builtin
, resolve
, require
, def
are all resolved at build / asset bundling phase./sample
folder for the input and output. The input is a bundle of size 404KB and copy paste the output bundle into https://try.terser.org/ with options as
{
toplevel: true,
compress: {
toplevel: true
},
mangle: {
toplevel: true
},
output: {},
parse: {},
rename: {},
}
The minified output will now be 250KB.
transform
in the Lasso config or be used as a plugin.
{
"plugins": [
"lasso-less",
"lasso-autoprefixer",
"lasso-marko",
"lasso-minify-transpile-inline",
"rollup-plugin-lasso",
{
"plugin": "lasso-inline-slots",
"config": {
"inlineSlots": [
"inline"
]
}
}
],
"require": {
"lastSlot": "inline",
"transforms": [
"lasso-babel-env"
]
},
"outputDir": "static",
"minify": true,
"minifyInlineOnly": true,
"bundlingEnabled": true,
"resolveCssUrls": true,
"noConflict": "gh-fe",
"cacheProfile": "production"
}
Now, the above output would cause Lasso to dump the final minfied output bundled under${PROJECT_DIR}/static
.
const { readFileSync, writeFileSync } = require('fs');
const { optimizeSingleSourceFile } = require('lasso-optimizer');
const code = readFileSync('static/my-awesome-bundle.js', 'utf8');
const result = optimizeSingleSourceFile(code);
writeFileSync('static/optimized-bundle.js', 'utf8');
// now proceed to upload to resource server.