Skip to content

Commit

Permalink
Merge pull request #14 from zoobestik/webpack-4-warning
Browse files Browse the repository at this point in the history
Fix webpack 4.x deprecation warning (closes #13)
  • Loading branch information
zoobestik authored Apr 4, 2018
2 parents 54256a9 + 5a90d0d commit 55b8201
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ const getOutputAssetFilename = postfix => file => {
return path.format(parsed);
};


/*
New webpack 4 API,
for webpack 2-3 compatibility used .plugin('...', cb)
*/
const unCamelCase = str => str.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`);

const pluginCompatibility = (caller, hook, cb) => {
if (caller.hooks) {
caller.hooks[hook].tap('csso-webpack-plugin', cb);
} else {
caller.plugin(unCamelCase(hook), cb);
}
};

export default class CssoWebpackPlugin {
constructor(opts, filter) {
this.options = opts;
Expand Down Expand Up @@ -53,10 +68,10 @@ export default class CssoWebpackPlugin {
}

apply(compiler) {
compiler.plugin('compilation', compilation => {
pluginCompatibility(compiler, 'compilation', compilation => {
const options = this.options;

compilation.plugin('optimize-chunk-assets', (chunks, done) => {
pluginCompatibility(compilation, 'optimizeChunkAssets', (chunks, done) => {
async.forEach(chunks, (chunk, chunked) => {
async.forEach(chunk.files, (file, callback) => {
try {
Expand Down

0 comments on commit 55b8201

Please sign in to comment.