diff --git a/.gitignore b/.gitignore index 5148e52..a104f2b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ logs *.log npm-debug.log* +.DS_Store +.idea # Runtime data pids diff --git a/styleguide-webpack-plugin.js b/styleguide-webpack-plugin.js index 6f4ad75..ddbe570 100644 --- a/styleguide-webpack-plugin.js +++ b/styleguide-webpack-plugin.js @@ -21,47 +21,53 @@ function StyleguideWebpackPlugin (options) { StyleguideWebpackPlugin.prototype.apply = function (compiler) { const self = this; - compiler.plugin('after-emit', function (compilation, callback) { - // Reset the asset arrays. - self.webpackCss = []; - self.webpackJs = []; + compiler.hooks.afterEmit.tapAsync( + { + name: 'Compile Stylguide', + }, function (compilation, callback) { + // Reset the asset arrays. + self.webpackCss = []; + self.webpackJs = []; - for (const filename in compilation.assets) { - const assetPath = '../' + filename; - // TODO find best way to determine order of assets from webpack. + for (const filename in compilation.assets) { + const assetPath = '../' + filename; + // TODO find best way to determine order of assets from webpack. - if (/\.js$/.test(filename)) { - // JS file. - if (!self.webpackJs.includes(assetPath)) { - if (/hot-update\.js/.test(filename)) { - // Place hot-update last. - self.webpackJs.push(assetPath); - } else { - self.webpackJs.unshift(assetPath); + if (/\.js$/.test(filename)) { + // JS file. + if (!self.webpackJs.includes(assetPath)) { + if (/hot-update\.js/.test(filename)) { + // Place hot-update last. + self.webpackJs.push(assetPath); + } else { + self.webpackJs.unshift(assetPath); + } + } + } else if (/\.css$/.test(filename)) { + // CSS file. + if (!self.webpackCss.includes(assetPath)) { + self.webpackCss.unshift(assetPath); + } } } - } else if (/\.css$/.test(filename)) { - // CSS file. - if (!self.webpackCss.includes(assetPath)) { - self.webpackCss.unshift(assetPath); - } - } - } - callback(); - }); + callback(); + }); - compiler.plugin('done', function () { - self.options.css = self.options.css || []; - self.options.js = self.options.js || []; - // Add the webpack assets. - const kssOptions = Object.assign({}, self.options, { - css: self.options.css.concat(self.webpackCss), - js: self.options.js.concat(self.webpackJs) - }); + compiler.hooks.done.tapAsync( + { + name: 'Finish Stylguide', + }, function () { + self.options.css = self.options.css || []; + self.options.js = self.options.js || []; + // Add the webpack assets. + const kssOptions = Object.assign({}, self.options, { + css: self.options.css.concat(self.webpackCss), + js: self.options.js.concat(self.webpackJs) + }); - kss(kssOptions); - }); + kss(kssOptions); + }); }; module.exports = StyleguideWebpackPlugin;