Skip to content

Commit

Permalink
fix: update the code of fetching plugin's name (#32)
Browse files Browse the repository at this point in the history
to be compatible of old HtmlRspackPlugin and HtmlWebpackPlugin
  • Loading branch information
xfsnowind authored Oct 10, 2024
1 parent cfb5521 commit a5dde48
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
16 changes: 15 additions & 1 deletion dist/makeRspackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,21 @@ exports.CYPRESS_RSPACK_ENTRYPOINT = path.resolve(__dirname, 'browser.js');
*/
function modifyRspackConfigForCypress(rspackConfig) {
if (rspackConfig === null || rspackConfig === void 0 ? void 0 : rspackConfig.plugins) {
rspackConfig.plugins = rspackConfig.plugins.filter((plugin) => plugin && !removeList.includes(plugin.constructor.name));
rspackConfig.plugins = rspackConfig.plugins.filter((plugin) => {
if (plugin) {
let pluginName = '';
try {
// NOTE: this is to be compatible the old version htmlRspackPlugin, to get its correct name
pluginName =
'raw' in plugin ? plugin.raw({ options: { output: {} } }).name : plugin.constructor.name;
}
catch (_a) {
pluginName = plugin.constructor.name;
}
return !removeList.includes(pluginName);
}
return false;
});
}
delete rspackConfig.entry;
delete rspackConfig.output;
Expand Down
17 changes: 14 additions & 3 deletions src/makeRspackConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,20 @@ export const CYPRESS_RSPACK_ENTRYPOINT = path.resolve(__dirname, 'browser.js')
*/
function modifyRspackConfigForCypress(rspackConfig: Partial<Configuration>) {
if (rspackConfig?.plugins) {
rspackConfig.plugins = rspackConfig.plugins.filter(
(plugin) => plugin && !removeList.includes(plugin.constructor.name),
)
rspackConfig.plugins = rspackConfig.plugins.filter((plugin) => {
if (plugin) {
let pluginName: string = ''
try {
// NOTE: this is to be compatible the old version htmlRspackPlugin, to get its correct name
pluginName =
'raw' in plugin ? plugin.raw({ options: { output: {} } }).name : plugin.constructor.name
} catch {
pluginName = plugin.constructor.name
}
return !removeList.includes(pluginName)
}
return false
})
}

delete rspackConfig.entry
Expand Down

0 comments on commit a5dde48

Please sign in to comment.