https://github.com/duydang2311/svelte-preprocess-uuid
Svelte compile-time UUID generation preprocessor
https://github.com/duydang2311/svelte-preprocess-uuid
svelte svelte-preprocessor uuid
Last synced: 8 months ago
JSON representation
Svelte compile-time UUID generation preprocessor
- Host: GitHub
- URL: https://github.com/duydang2311/svelte-preprocess-uuid
- Owner: duydang2311
- License: gpl-3.0
- Created: 2022-06-24T12:12:19.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-06-24T17:39:04.000Z (over 3 years ago)
- Last Synced: 2025-03-02T09:19:41.095Z (8 months ago)
- Topics: svelte, svelte-preprocessor, uuid
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/svelte-preprocess-uuid
- Size: 23.4 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# svelte-preprocess-uuid
## What is it?
It generates an ID at compile-time, which can be used for your DOM elements.
**Input**
```svelte
const uuid_1 = '$';
let uuid_2 = '$';
var uuid_3 = '$';
console.log(uuid_1);
console.log(uuid_2);
Label for {uuid_1}
Label for {uuid_2}
```
**Output**
```svelte
console.log('ac3dc94b-b448-456e-bf61-d886745a8bb4');
console.log('3dc94bb4-4855-4ebf-a1d8-86745a8bb48e');
Label for "ac3dc94b-b448-456e-bf61-d886745a8bb4"
Label for "3dc94bb4-4855-4ebf-a1d8-86745a8bb48e"
```
## Installation
```
npm i --save-dev svelte-preprocess-uuid
```
Next, add it to svelte preprocessor group in `rollup.config.js`:
```js
import uuid from 'svelte-preprocess-uuid';
export default {
plugins: [
svelte({ preprocess: uuid })
]
}
// or if you are using another preprocessor, like svelte-preprocess
export default {
plugins: [
svelte({
preprocess: [
uuid,
sveltePreprocess({}),
],
})
]
}
```
## Known issues
- The uniqueness is not guaranteed when a Svelte file is imported multiple times, since every Svelte file is only preprocessed once.