Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix webpack chunk loading for GitHub Pages deployment
Problem
With webpack code splitting enabled, chunk files (e.g.,
841.mashlib.js) were failing to load on GitHub Pages:https://solidos.github.io/mashlib/dist/browse.html- chunks tried to load fromhttps://solidos.github.io/841.mashlib.jsinstead ofhttps://solidos.github.io/mashlib/dist/841.mashlib.jsError:
ChunkLoadError: Loading chunk 841 failedRoot cause: Webpack's
publicPathwas set to/(absolute root), which works fine for localhost but not for GitHub Pages where files are deployed under/mashlib/dist/.Solution
Added environment-based
publicPathconfiguration to support both deployment environments:publicPath: '/'for localhost deploymentspublicPath: '/mashlib/dist/'viaPUBLIC_PATHenvironment variableChanges
1.
webpack.config.mjsUpdated
publicPathto read from environment variable:2.
package.jsonAdded new build script for GitHub Pages:
3.
.github/workflows/ci.ymlUpdated
gh-pagesjob to rebuild with the correct publicPath:This ensures:
buildjob usesnpm run build(default publicPath for npm package)gh-pagesjob usesnpm run build:ghpages(GitHub Pages specific publicPath)Usage
For localhost deployment (default):
Chunks will load from:
/841.mashlib.jsFor GitHub Pages deployment:
Chunks will load from:
/mashlib/dist/841.mashlib.jsTesting
Both deployment scenarios now work correctly:
npm run build- chunks load from/841.mashlib.jsnpm run build:ghpages- chunks load from/mashlib/dist/841.mashlib.js