X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2Findex.js;h=0c620bf83761c0812594953c4e6feef0ea1472d0;hb=d841685e41e7b37ea4ce6228157af3888ca13a83;hp=13bc5aedbac35b987f531d70523f71257c99fabd;hpb=e227b9ac6fd39aa90e2ecd5b443cb687aeb8cdf7;p=github%2Ffretlink%2Fpurs-loader.git 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);