CSS get removed when project init
Question
Hi,
I'm trying to import utility classes into grapes js. My issue is that grapes remove them if they are not use by an element in the canvas. I'm building a custom panel to link to my CSS variables (CSS custom properties) to manage this classes in grapes.
How can I import my CSS and keep all the classes?
I have created a small demo of my issue https://codesandbox.io/s/musing-moore-1tswh?file=/index.js
Go in index.html and you will see all the CSS. When clicking on view code, you will see most of the CSS have been removed.
Thanks a lot
Answers (3)
grapesJS does not deal with css directly it first parses it into a CSSOM and uses that in the editor so a class will not show up in the code preview unless there is a component in the editor canvas using it. Your classes will be imported dynamically as they are used in the editor canvas.
You could load the stylesheet externally during init and remove it from the index.html altogether
canvas:{
styles: [
'path/to/stylesheet'
]
}
You can also check the SelectorManager and CssComposer api reference
Thanks @Ju99ernaut, do you know if there is anyway to add some css and make it available in the canvas and as well have it in the export?
Related Questions and Answers
Continue research with similar issue discussions.
Issue #966
[QUESTION] How to load external CSS file into Grapes Editor?
Hey, During my editor = grapesjs.init(), I want to load an external CSS file into the canvas using @import url(...). So when I use my custo...
Issue #2388
[Question] - How to import styles from <link> to be rendered when dragging block to canvas
My situation: I'm slowly importing some of my custom made UI components in ReactJS to GrapesJS. Now, I am able to render the component prop...
Issue #3832
BUG: The css classes are removed and the autogenerated ids for each html tags gets changed ( Example : ivj5m-2) after each reload
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome Reproducible demo link Not there De...
Issue #6543
BUG: Panel not removed
GrapesJS version [x] I confirm to use the latest version of GrapesJS What browser are you using? chrome Reproducible demo link none Describ...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.