Skip to content

Commit

Permalink
shell: experiment with esbuild and terser
Browse files Browse the repository at this point in the history
  • Loading branch information
takase1121 committed Jun 5, 2024
1 parent 51dce49 commit ddab90c
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 25 deletions.
2 changes: 1 addition & 1 deletion scripts/gh-pages-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ $file_packager "${dest_dir}/lite-xl-files.json" \
--no-force --no-node --use-preload-cache --use-preload-plugins \
--quiet --js-output="${dest_dir}/lite-xl-files.js"
# this file is rather big, run closure compiler over the output
node shell/closure.js "${dest_dir}/lite-xl-files.min.js" "${dest_dir}/lite-xl-files.js"
node shell/esbuild.js "${dest_dir}/lite-xl-files.min.js" true "${dest_dir}/lite-xl-files.js"
# these files can be removed for final distribution
rm -rf "$(pwd)/${dest_dir}/lite-xl.js" "$(pwd)/${dest_dir}/lite-xl-files.js" \
"${data_dir}" "$(pwd)/${dest_dir}/doc"
Expand Down
22 changes: 18 additions & 4 deletions shell/esbuild.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
const installAndRun = require("./deps");

installAndRun((outputFile, minify, ...entrypoints) => {
installAndRun((outputFile, minify, entrypoint, ...inject) => {
const esbuild = require("esbuild");
esbuild.buildSync({
entryPoints: entrypoints,
const { minify_sync } = require("terser");
const { writeFileSync } = require("fs");
const output = esbuild.buildSync({
entryPoints: [entrypoint],
bundle: true,
minify: minify === "true",
minify: entrypoint.endsWith("js") ? false : minify == "true",
target: "es2017",
logLevel: "info",
outfile: outputFile,
write: !entrypoint.endsWith("js"),
inject,
});
if (entrypoint.endsWith("js") && minify == "true") {
const minified = minify_sync(output.outputFiles[0].text, {
compress: {
booleans_as_integers: true,
ecma: 2017,
passes: 3,
},
});
writeFileSync(outputFile, minified.code, { encoding: "utf8" });
}
});
23 changes: 5 additions & 18 deletions shell/js/meson.build
Original file line number Diff line number Diff line change
@@ -1,31 +1,18 @@
main_src = [
'main.js',
'idbsync.js',
'fs.js',
]

main_bundle = custom_target('main.bundle.js',
input: main_src,
output: 'main.bundle.js',
depend_files: [package_lock, esbuild_script],
# esbuild only needs the entrypoint to figure out what files to bundle
command: [node_exe, esbuild_script , '@OUTPUT@', 'false', '@INPUT0@'])

custom_target('main.js',
input: [lite_exe, main_bundle],
input: ['main.js', lite_exe],
output: 'main.js',
build_by_default: true,
depend_files: [package_lock, closure_script, closure_externs],
depend_files: [package_lock, esbuild_script],
install: true,
install_dir: lite_bindir,
# the first must be the entrypoint
command: [node_exe, closure_script , '@OUTPUT@', '@INPUT@'])
# esbuild only needs the entrypoint to figure out what files to bundle
command: [node_exe, esbuild_script , '@OUTPUT@', 'true', '@INPUT@'])

custom_target('advanced.js',
input: 'advanced.js',
output: 'advanced.js',
depend_files: [package_lock, esbuild_script],
build_by_default: true,
depend_files: [package_lock, esbuild_script],
install: true,
install_dir: lite_bindir,
# esbuild only needs the entrypoint to figure out what files to bundle
Expand Down
134 changes: 133 additions & 1 deletion shell/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion shell/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"devDependencies": {
"esbuild": "^0.21.1",
"google-closure-compiler": "^20240317.0.0",
"prettier": "^3.2.5"
"prettier": "^3.2.5",
"terser": "^5.31.0"
},
"dependencies": {
"fflate": "^0.8.2"
Expand Down

0 comments on commit ddab90c

Please sign in to comment.