I need a global variable for the duration of the plugin, or any advice #7359
-
Hello! I am creating an SWC plugin. I will be as brief as possible. The user can style HTML (jsx) elements with attributes. The plugin adds a class attribute with a unique id. my problem: I created a global variable
When I find the style attribute, I put the style on that line, and write the whole line to a file But this variable is cleared for each component.
During the processing of "MyComp", the styles of the "Home" component will be removed. Help me please. I need a global variable for the duration of the plugin, or any advice. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Answered in here and for the visibility :#4997 (reply in thread) It's not about fs more about the approach: if components are separated into different files, no, there's no |
Beta Was this translation helpful? Give feedback.
-
Just to be clear, if it's in single file have multiple components that you need to store states, in-memory struct property should work. However SWC does not provides guaranteed order of file process, or lifecycles that each transform (not only plugin) access global states in a specific order. |
Beta Was this translation helpful? Give feedback.
Answered in here and for the visibility :#4997 (reply in thread) It's not about fs more about the approach: if components are separated into different files, no, there's no
global
lifetime you can expect to store-at-read once some states.