diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/index.js | 24 |
1 files 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) { | |||
132 | 132 | ||
133 | CACHE_VAR.installed = true; | 133 | CACHE_VAR.installed = true; |
134 | 134 | ||
135 | // invalidate loader CACHE_VAR when bundle is marked as invalid (in watch mode) | 135 | const invalidCb = () => { |
136 | this._compiler.plugin('invalid', () => { | ||
137 | debugVerbose('invalidating loader CACHE_VAR'); | 136 | debugVerbose('invalidating loader CACHE_VAR'); |
138 | 137 | ||
139 | CACHE_VAR = { | 138 | CACHE_VAR = { |
@@ -149,10 +148,16 @@ module.exports = function purescriptLoader(source, map) { | |||
149 | installed: CACHE_VAR.installed, | 148 | installed: CACHE_VAR.installed, |
150 | srcOption: [] | 149 | srcOption: [] |
151 | }; | 150 | }; |
152 | }); | 151 | } |
153 | 152 | ||
154 | // add psc warnings to webpack compilation warnings | 153 | // invalidate loader CACHE_VAR when bundle is marked as invalid (in watch mode) |
155 | this._compiler.plugin('after-compile', (compilation, callback) => { | 154 | if(this._compiler.hooks){ |
155 | this._compiler.hooks.invalid.tap('purs-loader', invalidCb); | ||
156 | } else { | ||
157 | this._compiler.plugin('invalid', invalidCb); | ||
158 | } | ||
159 | |||
160 | const afterCompileCb = (compilation, callback) => { | ||
156 | CACHE_VAR.warnings.forEach(warning => { | 161 | CACHE_VAR.warnings.forEach(warning => { |
157 | compilation.warnings.push(warning); | 162 | compilation.warnings.push(warning); |
158 | }); | 163 | }); |
@@ -162,7 +167,14 @@ module.exports = function purescriptLoader(source, map) { | |||
162 | }); | 167 | }); |
163 | 168 | ||
164 | callback() | 169 | callback() |
165 | }); | 170 | } |
171 | |||
172 | // add psc warnings to webpack compilation warnings | ||
173 | if(this._compiler.hooks) { | ||
174 | this._compiler.hooks.afterCompile.tapAsync('purs-loader', afterCompileCb); | ||
175 | } else { | ||
176 | this._compiler.plugin('after-compile', afterCompileCb); | ||
177 | } | ||
166 | } | 178 | } |
167 | 179 | ||
168 | const psModuleName = PsModuleMap.matchModule(source); | 180 | const psModuleName = PsModuleMap.matchModule(source); |