Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/metonym/spre
Svelte preprocessing utilities
https://github.com/metonym/spre
preprocess svelte
Last synced: about 1 month ago
JSON representation
Svelte preprocessing utilities
- Host: GitHub
- URL: https://github.com/metonym/spre
- Owner: metonym
- License: mit
- Created: 2021-08-07T00:29:56.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-08-07T00:47:33.000Z (over 3 years ago)
- Last Synced: 2024-11-16T07:48:21.447Z (about 2 months ago)
- Topics: preprocess, svelte
- Language: TypeScript
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# spre
> Svelte preprocessing utilities
## Installation
**Yarn**
```sh
yarn add -D spre
```**NPM**
```sh
npm i -D spre
```## Usage
### onImportDeclaration
Use `onImportDeclaration` to re-write imports in the script block.
```diff
- import { Ad as Ad2 } from "svelte-lib";
- import { Bridge } from "svelte-lib";
+ import Ad2 from "svelte-lib/lib/Ad.svelte";
+ import Bridge from "svelte-lib/lib/Bridge.svelte";
``````js
// svelte.config.js
import spre from "spre";export default {
preprocess: [
spre({
onImportDeclaration({ sourceName, importName, localName }) {
return `import ${localName} from "${sourceName}/lib/${importName}.svelte";`;
},
}),
],
};
```Example that only re-writes non-default and not namespaced imports from a specific library:
```js
spre({
onImportDeclaration({ sourceName, importName, localName }) {
if (sourceName !== "svelte-lib") return;
if (isDefaultImport || !importName) return;
return `import ${localName} from "${sourceName}/lib/${importName}.svelte";`;
},
}),
```## License
[MIT](LICENSE)