bundle.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * ParcelJS Bundle Configuration.
  3. *
  4. * @see https://parceljs.org/api.html
  5. */
  6. const Bundler = require('parcel-bundler');
  7. // Bundler options common to all bundle jobs.
  8. const options = {
  9. logLevel: 2,
  10. cache: true,
  11. watch: false,
  12. minify: true,
  13. outDir: './dist',
  14. publicUrl: '/static',
  15. };
  16. // Get CLI arguments for optional overrides.
  17. const args = process.argv.slice(2);
  18. // Allow cache disabling.
  19. if (args.includes('--no-cache')) {
  20. options.cache = false;
  21. }
  22. // Style (SCSS) bundle jobs. Generally, everything should be bundled into netbox.css from main.scss
  23. // unless there is a specific reason to do otherwise.
  24. const styles = [
  25. ['styles/_external.scss', 'netbox-external.css'],
  26. ['styles/_light.scss', 'netbox-light.css'],
  27. ['styles/_dark.scss', 'netbox-dark.css'],
  28. ['styles/_elevations.scss', 'rack_elevation.css'],
  29. ];
  30. // Script (JavaScript) bundle jobs. Generally, everything should be bundled into netbox.js from
  31. // index.ts unless there is a specific reason to do otherwise.
  32. const scripts = [
  33. ['src/index.ts', 'netbox.js'],
  34. ['src/jobs.ts', 'jobs.js'],
  35. ['src/device/lldp.ts', 'lldp.js'],
  36. ['src/device/config.ts', 'config.js'],
  37. ['src/device/status.ts', 'status.js'],
  38. ];
  39. /**
  40. * Run style bundle jobs.
  41. */
  42. async function bundleStyles() {
  43. for (const [input, outFile] of styles) {
  44. const instance = new Bundler(input, { outFile, ...options });
  45. await instance.bundle();
  46. }
  47. }
  48. /**
  49. * Run script bundle jobs.
  50. */
  51. async function bundleScripts() {
  52. for (const [input, outFile] of scripts) {
  53. const instance = new Bundler(input, { outFile, ...options });
  54. await instance.bundle();
  55. }
  56. }
  57. /**
  58. * Run all bundle jobs.
  59. */
  60. async function bundleAll() {
  61. if (args.includes('--styles')) {
  62. // Only run style jobs.
  63. return await bundleStyles();
  64. } else if (args.includes('--scripts')) {
  65. // Only run script jobs.
  66. return await bundleScripts();
  67. }
  68. await bundleStyles();
  69. await bundleScripts();
  70. }
  71. bundleAll();