Skip to content

Commit

Permalink
Make external libs builder leveraging esbuild (rstudio#3357)
Browse files Browse the repository at this point in the history
  • Loading branch information
schloerke authored Apr 7, 2021
1 parent 850a628 commit fad21af
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 5 deletions.
7 changes: 6 additions & 1 deletion inst/www/shared/datepicker/js/bootstrap-datepicker.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inst/www/shared/ionrangeslider/js/ion.rangeSlider.min.js

Large diffs are not rendered by default.

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

63 changes: 63 additions & 0 deletions srcts/esbuild.external_libs.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import {readdirSync, unlinkSync, writeFileSync} from "fs";
import esbuild from "esbuild";
import globalsPlugin from "esbuild-plugin-globals";

// import process from "process";
// let watch = process.argv.length >= 3 && process.argv[2] == "--watch";

let instdir = "../inst/";
let outdir = instdir + "/www/shared/";

let opts = {
bundle: false,
watch: false,
target: "es5",
sourcemap: false,
};

console.log("Building datepicker");
const locale_files = readdirSync(instdir + "www/shared/datepicker/js/locales/")

let require_files = locale_files.map(function(filename) {
return `require("./locales/${ filename }");`;
}).join("\n");

let tmpfile = instdir + "www/shared/datepicker/js/temp.js";
writeFileSync(tmpfile,
`require("./bootstrap-datepicker.js");
${require_files}`)
await esbuild.build({
...opts,
plugins:[
globalsPlugin({
jquery: "window.jQuery",
})
],
bundle: true,
entryPoints: [tmpfile],
outfile: instdir + "www/shared/datepicker/js/bootstrap-datepicker.min.js",
external: ['jquery'],
minify: true,
});
// Clean up
unlinkSync(tmpfile);

console.log("Building ionrangeslider");
await esbuild.build({
...opts,
entryPoints: [
instdir + "www/shared/ionrangeslider/js/ion.rangeSlider.js"
],
outfile: instdir + "www/shared/ionrangeslider/js/ion.rangeSlider.min.js",
minify: true,
});

console.log("Building selectize");
await esbuild.build({
...opts,
entryPoints: [
instdir + "www/shared/selectize/accessibility/js/selectize-plugin-a11y.js"
],
outfile: instdir + "www/shared/selectize/accessibility/js/selectize-plugin-a11y.min.js",
minify: true,
});
3 changes: 2 additions & 1 deletion srcts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@
},
"scripts": {
"watch": "yarn run build_shiny --watch",
"build": "yarn run build_shiny",
"build": "yarn run build_shiny && yarn run bundle_external_libs",
"setup_build_shiny": "yarn run lint && yarn run typescript-check",
"build_shiny": "yarn run setup_build_shiny && yarn run bundle_shiny",
"bundle_shiny": "node esbuild.config.mjs",
"bundle_external_libs": "node esbuild.external_libs.mjs",
"bundle_shiny_parcel2": "parcel build -d ../inst/www/shared --no-minify -o shiny.js src/index.ts",
"watch_parcel2": "yarn run setup_build_shiny && parcel run -d ../inst/www/shared -o shiny.js srcjs/index.ts",
"replace_shiny_version2": "replace --silent '\"[^\"]+\"; // @VERSION@' \"\\\"`node -e 'console.log(require(\"readcontrol\").readSync(\"../DESCRIPTION\").version)'`\\\"; // @VERSION@\" src/shiny.ts",
Expand Down
2 changes: 1 addition & 1 deletion tools/updateIonRangeSlider.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ sass(


# Finally, run yarn build so the JS patches propogate to the minified files
withr::with_dir(rprojroot::find_package_root_file("tools"), system("yarn build"))
withr::with_dir(rprojroot::find_package_root_file("tools"), system("yarn bundle_external_libs"))

0 comments on commit fad21af

Please sign in to comment.