diff options
author | Rajat Sharma <lunasunkaiser@gmail.com> | 2019-03-10 18:23:45 +0530 |
---|---|---|
committer | eric <thul.eric@gmail.com> | 2019-03-10 08:53:45 -0400 |
commit | d841685e41e7b37ea4ce6228157af3888ca13a83 (patch) | |
tree | 7905e4d48a9504613523674753f607d3e81d49c5 | |
parent | e227b9ac6fd39aa90e2ecd5b443cb687aeb8cdf7 (diff) | |
download | purs-loader-d841685e41e7b37ea4ce6228157af3888ca13a83.tar.gz purs-loader-d841685e41e7b37ea4ce6228157af3888ca13a83.tar.zst purs-loader-d841685e41e7b37ea4ce6228157af3888ca13a83.zip |
Added hooks support (#122)
Closes #120
-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); |