cli.js 1017 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env node
  2. "use strict";
  3. // `module.enableCompileCache` is only available on Node.js >= 22.8.0
  4. // eslint-disable-next-line n/no-unsupported-features/node-builtins
  5. const { enableCompileCache } = require("node:module");
  6. if (enableCompileCache) {
  7. try {
  8. enableCompileCache();
  9. } catch {
  10. // Ignore errors
  11. }
  12. }
  13. // Prefer the local installation of `webpack-cli` when one exists. Run this
  14. // before requiring the (heavier) CLI implementation: a delegated run then never
  15. // loads it, and `WEBPACK_CLI_SKIP_IMPORT_LOCAL` skips loading `import-local` too.
  16. if (!process.env.WEBPACK_CLI_SKIP_IMPORT_LOCAL && require("import-local")(__filename)) {
  17. return;
  18. }
  19. process.title = "webpack";
  20. const WebpackCLI = require("../lib/webpack-cli").default;
  21. const runCLI = async (args) => {
  22. const cli = new WebpackCLI();
  23. try {
  24. await cli.run(args);
  25. } catch (error) {
  26. cli.logger.error(error);
  27. process.exit(2);
  28. }
  29. };
  30. // eslint-disable-next-line unicorn/prefer-top-level-await
  31. runCLI(process.argv);