Chapter 1: LWC Tutorial – LWC OSS
LWC OSS is an open-source LWC that would allow developers to use the LWC framework to build applications outside of the Salesforce system as well. LWC framework which we use inside the Salesforce system is considered as managed LWC.
Why was it required?
Earlier developers were using the different frameworks to build different applications for example Aura to build an app inside Salesforce and some other framework for applications outside the Salesforce environment. But now with LWC OSS developers can use the same framework to build both sides of applications
How is LWC OSS different than managed LWC?
LWC engine is the same in the case of both managed LWC and OSS, the difference is how they are configured at compile and run time level.
· Compile Time Differences
- No experimental API works in managed LWC
- Dynamic imports are not allowed ( We can only add static imports at the top of the file) Dynamic imports allow us to import any module or function on meeting certain criteria
- ES Lint rules are enforced ( by default base level rules) Linting is nothing but a statical analysis of code to report any syntax error or any bad constructs used in code
- $A is prohibited
- All the @salesforce imports are validated against the org (for example apex methods)
· Run time Differences
- In managed LWC we are using synthetic DOM to support old browsers
- You cant access the host element while in OSS you can.
- LWC modules are evaluated inside the lightning locker.
Note: Because of synthetic DOM you never see #shadowRoot in chrome while inspecting the components