-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add optional cssHref param to style-loader (#27)
* Add optional cssHref param to style-loader This uses a css href reload method rather than injecting an updated styl This makes styl property deletions reflect in the UI as well * Fix messaging * Use t=
- Loading branch information
Showing
5 changed files
with
32 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* eslint-env commonjs */ | ||
module.exports = function updateCssHref(cssLinkHref) { | ||
const cssLink = document.querySelector(`link[href][rel=stylesheet][href*='${cssLinkHref}']`); | ||
if (cssLink) { | ||
// Add hash param to css url to trigger style refresh | ||
// We use #t=.. so if css hasn't changed then webpack-dev-server can reply with a 304 Not modified | ||
// Which does a no-op for style calculation and paint | ||
const cssUrl = cssLink.getAttribute(`href`).split(`#`)[0]; | ||
cssLink.setAttribute(`href`, `${cssUrl}#t=${new Date().getTime()}`); | ||
console.info(`[HMR Panel] Refreshed ${cssUrl}`); | ||
} else { | ||
console.warn(`[HMR Panel] Could not find stylesheet matching '${cssLinkHref}' in document`); | ||
} | ||
}; |
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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