2

I am trying to access label in a component(Lightning web component).

import greeting from '@salesforce/label/c.xxxx;
import greeting from '@salesforce/label/c.yyyy;
...

I want to access all labels in one import.

So is it possible? Reason is: one of my component have lot of messages which we need to import. we want to avoid multiple import line for label in my component.

I was following salesforce article but didn't get there:

https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.create_labels

Or if is there other way around, if we can remove multiple time import?

2

I think fundamentally they want you to reference the labels one at a time so that dependencies are properly managed. E.g. you can't accidentally delete a label that's in use, and if you add the LWC to a package it will auto-include the label.

If you have a large list of labels you want to use in multiple components, maybe you could create a utility component that imports all the labels and then exposes them bundled together in one object via an @api method. Then your main component will have a cleaner list of imports.

Not the answer you're looking for? Browse other questions tagged or ask your own question.