Skip to content

Commit

Permalink
docs: adapt
Browse files Browse the repository at this point in the history
  • Loading branch information
lucagoslar committed Nov 10, 2022
1 parent 410ff02 commit a29db22
Showing 1 changed file with 91 additions and 7 deletions.
98 changes: 91 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,103 @@
## ts-pkg
## svelte-preprocess-sass-alias-import

This is a Boilerplate to create npm packages in TypeScript.
🗃 Import external stylesheets with the help of absolute paths.

[![build package and run tests](https://github.com/lucagoslar/ts-pkg/actions/workflows/main.yml/badge.svg)](https://github.com/lucagoslar/ts-pkg/actions/workflows/main.yml)
Though this package might also work in a different environment that uses sass, it should be noted that it serves the [legacy importer](https://sass-lang.com/documentation/js-api/modules#LegacyImporter) used by [svelte-preprocess](https://github.com/sveltejs/svelte-preprocess).

## Usage
[![build and test](https://github.com/lucagoslar/svelte-preprocess-sass-alias-import/actions/workflows/main.yml/badge.svg)](https://github.com/lucagoslar/svelte-preprocess-sass-alias-import/actions/workflows/main.yml)

## Setup

1. Import `SassAlias` from `svelte-preprocess-sass-alias-import`.

```ts
import { SassAlias } from 'svelte-preprocess-sass-alias-import';
```

2. Instantiate `SassAlias` and pass it an object containing your rules.

```ts
const alias = new SassAlias({
$var: 'src/scss',
@var: ["src", "scss"]
});
```

3. Add and bind the `SassAlias` instance to the project's preprocessor.
(Sample usage with SvelteKit.)

```js
// svelte.config.js
import preprocess from 'svelte-preprocess';

/** @type {import('@sveltejs/kit').Config} */
const config = {
preprocess: [
preprocess({
sass: {
importer: [alias.resolve.bind(alias)],
},
scss: {
importer: [alias.resolve.bind(alias)],
}, // Use for both sass and or scss
}),
],
};

export default config;
```

```ts
// vite.config.ts
// Only required if you want to import stylesheets into an already imported stylesheet

const config: UserConfig = {
css: {
preprocessorOptions: {
sass: {
importer: [alias.resolve.bind(alias)],
},
scss: {
importer: [alias.resolve.bind(alias)],
},
},
},
};
```

4. Import files using your predefined aliases.

```svelte
<!-- *.svelte -->
<style lang="scss">
@import "$var/main.scss";
</style>
```

```svelte
<!-- *.svelte -->
<style lang="sass">
@use "@var/main.scss"
</style>
```

```scss
// *.scss
@use '@var/main.scss';
```

## Contribute

Install all (dev-)dependencies by running the following.

```
pnpm i
npm i
```

Make sure [husky](https://github.com/typicode/husky) is being installed too.

```
pnpm run prepare
npm run prepare
```

\
Expand All @@ -24,5 +106,7 @@ _And off we go …_
Build this project with the following.

```
pnpm run build
npm run build
```

Contributions of any kind are very much appreciated.

0 comments on commit a29db22

Please sign in to comment.