NoEmitOnErrorsPlugin.js 725 B

123456789101112131415161718192021222324252627282930
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. /** @typedef {import("./Compiler")} Compiler */
  7. const PLUGIN_NAME = "NoEmitOnErrorsPlugin";
  8. class NoEmitOnErrorsPlugin {
  9. /**
  10. * Apply the plugin
  11. * @param {Compiler} compiler the compiler instance
  12. * @returns {void}
  13. */
  14. apply(compiler) {
  15. compiler.hooks.shouldEmit.tap(PLUGIN_NAME, compilation => {
  16. if (compilation.getStats().hasErrors()) return false;
  17. });
  18. compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
  19. compilation.hooks.shouldRecord.tap(PLUGIN_NAME, () => {
  20. if (compilation.getStats().hasErrors()) return false;
  21. });
  22. });
  23. }
  24. }
  25. module.exports = NoEmitOnErrorsPlugin;