Use external CSS files from .styles.scss source #5489
Merged
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.
This PR provides a potential solution for using external stylesheets in our wizard web components. The webpack config changes basically:
.scss
source code and translates it to CSS usingsass-loader
type: "asset/resource"
which will emit a separate file and export the URL of that generated file by default.css
fileOnce we've generated the CSS file we can import the
.scss
source in our web component to get the URL of the built file, then create a link pointing to that URL.This whole process doesn't seem to work if we run things through
MiniCssExtractPlugin.loader
, so I've given the file a.styles.scss
extension so that we can specify different Webpack rules for CSS we want to load into web components. (This was inspired by this article - I'm open to other naming conventions.)I'm not 100% sure this is going to work in production environments, but it's working well for me locally, so seems like a starting point at least.
--
As a little experiment to check that we could load Protocol styles, I copied the contents of
_protocol.scss
intoform-wizard.styles.scss
and added an import for the protocol button component. This was the result: