Skip to content

Commit

Permalink
Remove duplicated publicPath (#27)
Browse files Browse the repository at this point in the history
* Remove duplicated publicPath

* Add test

* Remove dead code

---------

Co-authored-by: Joel Denning <[email protected]>
  • Loading branch information
karoldeland and joeldenning authored Sep 21, 2024
1 parent bddc2a4 commit 358f0d7
Show file tree
Hide file tree
Showing 4 changed files with 3,014 additions and 2,431 deletions.
35 changes: 8 additions & 27 deletions lib/standalone-single-spa.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,34 +64,15 @@ class StandaloneSingleSpaPlugin {
}
apply(compiler) {
compiler.hooks.compilation.tap(pluginName, (compilation) => {
let publicPath;

const oldHtmlPlugin = !this.options.HtmlWebpackPlugin.getHooks;

if (oldHtmlPlugin) {
compilation.plugin(
"html-webpack-plugin-alter-asset-tags",
(data, cb) => {
this.modifyScripts({ publicPath, scripts: data.body });
}
);
} else {
this.options.HtmlWebpackPlugin.getHooks(
compilation
).beforeAssetTagGeneration.tap(pluginName, (data) => {
publicPath = data.assets.publicPath;
});

this.options.HtmlWebpackPlugin.getHooks(compilation).alterAssetTags.tap(
pluginName,
(data) => {
this.modifyScripts({ publicPath, scripts: data.assetTags.scripts });
}
);
}
this.options.HtmlWebpackPlugin.getHooks(compilation).alterAssetTags.tap(
pluginName,
(data) => {
this.modifyScripts({ scripts: data.assetTags.scripts });
}
);
});
}
modifyScripts({ publicPath, scripts }) {
modifyScripts({ scripts }) {
if (scripts.modifiedBySingleSpaStandalonePlugin) {
throw Error(
`standalone-single-spa-webpack-plugin: You have two separate instances of standalone-single-spa-webpack-plugin in your webpack config. If using webpack-config-single-spa or vue-cli-plugin-single-spa, you do not need to manually add the standalone plugin since it's already added by those projects.`
Expand All @@ -113,7 +94,7 @@ class StandaloneSingleSpaPlugin {

scripts.modifiedBySingleSpaStandalonePlugin = true;

let mainScriptSrc = (publicPath || "/") + mainScript.attributes.src;
let mainScriptSrc = "/" + mainScript.attributes.src;
if (mainScriptSrc.startsWith("//")) {
// html-webpack-plugin@3 provides script src differently than v4, so this
// fixes things for v3
Expand Down
Loading

0 comments on commit 358f0d7

Please sign in to comment.