From d841685e41e7b37ea4ce6228157af3888ca13a83 Mon Sep 17 00:00:00 2001 From: Rajat Sharma Date: Sun, 10 Mar 2019 18:23:45 +0530 Subject: Added hooks support (#122) Closes #120 --- src/index.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/index.js b/src/index.js index 13bc5ae..0c620bf 100644 --- a/src/index.js +++ b/src/index.js @@ -132,8 +132,7 @@ module.exports = function purescriptLoader(source, map) { CACHE_VAR.installed = true; - // invalidate loader CACHE_VAR when bundle is marked as invalid (in watch mode) - this._compiler.plugin('invalid', () => { + const invalidCb = () => { debugVerbose('invalidating loader CACHE_VAR'); CACHE_VAR = { @@ -149,10 +148,16 @@ module.exports = function purescriptLoader(source, map) { installed: CACHE_VAR.installed, srcOption: [] }; - }); + } - // add psc warnings to webpack compilation warnings - this._compiler.plugin('after-compile', (compilation, callback) => { + // invalidate loader CACHE_VAR when bundle is marked as invalid (in watch mode) + if(this._compiler.hooks){ + this._compiler.hooks.invalid.tap('purs-loader', invalidCb); + } else { + this._compiler.plugin('invalid', invalidCb); + } + + const afterCompileCb = (compilation, callback) => { CACHE_VAR.warnings.forEach(warning => { compilation.warnings.push(warning); }); @@ -162,7 +167,14 @@ module.exports = function purescriptLoader(source, map) { }); callback() - }); + } + + // add psc warnings to webpack compilation warnings + if(this._compiler.hooks) { + this._compiler.hooks.afterCompile.tapAsync('purs-loader', afterCompileCb); + } else { + this._compiler.plugin('after-compile', afterCompileCb); + } } const psModuleName = PsModuleMap.matchModule(source); -- cgit v1.2.3