I am currently developing a Single Page Application (SPA) using Vue (specifically Quasar), and I have the following requirements:
- Load the contents of a CSS file into a JavaScript variable or Vue data property dynamically
- The CSS file should be generated from a SCSS file at build time
Instead of loading a pre-made CSS file, I want to write the CSS code using SASS. Additionally, I do not want to compile the CSS from SCSS each time the app loads.
Here is what I have in mind for the workflow:
- Create the CSS in a specific SCSS file within my project structure
- Compile this SCSS file into a CSS file during build time or run-dev time
- Then, in one of my Vue components, load the resulting CSS code as a string into a variable at runtime
The purpose of this setup is to pass the CSS code into an iframe using postMessage and have the iframe apply the styles to the page using CSSStyleSheet's insertRule() method.
What steps should I take to configure my project and packages to achieve this? It seems like I may need to use the raw-loader, but how can I ensure that the CSS file is prepared correctly during the project build so that the raw-loader can access it at runtime?