Skip to content

Commit

Permalink
Updated peerDependencies to webpack5 and webpack4.
Browse files Browse the repository at this point in the history
  • Loading branch information
visto9259 committed Jan 17, 2022
1 parent 3e43a61 commit a254693
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,16 @@ class PhpWebpackPlugin {
output += PHPAssocArrayUtils.arrayKeyWithGT(name, 1);
output += PHPAssocArrayUtils.openingBracket(0);
chunks.forEach((chunk, key) => {
let asset = path.join(compiler.options.output.publicPath, assets[key]);
let asset;
// if Webpack 5, the asset is an object
if (assets[key] instanceof Object) {
if (assets[key].name) asset = path.join(compiler.options.output.publicPath, assets[key].name);
else console.error('Unsupported asset object');
}
// if Webpack 4, the asset is a string
else if (typeof assets[key] === 'string') asset = path.join(compiler.options.output.publicPath, assets[key]);
// if it changes again
else console.error('Unsupported asset object');
asset = asset.replace(/\\/gm,'/');
output += PHPAssocArrayUtils.arrayKeyWithGT(chunk, 2) + ` '${asset}',\n`
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"url": "https://github.com/visto9259/php-webpack-plugin.git"
},
"peerDependencies": {
"webpack": "^5.0.0"
"webpack": "^5.0.0 || ^4.0.0"
}
}

0 comments on commit a254693

Please sign in to comment.