Skip to content

Commit f4b9141

Browse files
committed
Update readme
1 parent 87f8e91 commit f4b9141

File tree

1 file changed

+46
-54
lines changed

1 file changed

+46
-54
lines changed

README.md

Lines changed: 46 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -546,10 +546,33 @@ Pass an object of the following properties
546546
| `parseStyleTag` | `{Boolean}` | `true` | Enable parsing on style tag |
547547
| `useAsDefaultScoping` | `{Boolean}` | `false` | Replace svelte scoping globally |
548548

549+
**`getLocalIdent`**
550+
551+
Customize the creation of the classname instead of relying on the built-in function.
552+
553+
```ts
554+
function getLocalIdent(
555+
context: {
556+
context: string, // the context path
557+
resourcePath: string, // path + filename
558+
},
559+
localIdentName: {
560+
template: string, // the template rule
561+
interpolatedName: string, // the built-in generated classname
562+
},
563+
className: string, // the classname string
564+
content: {
565+
markup: string, // the markup content
566+
style: string, // the style content
567+
}
568+
): string {
569+
return `your_generated_classname`;
570+
}
571+
```
549572

550573
**`hashSeeder`**
551574

552-
Set the resource content of `[hash]` and `[contenthash]`.
575+
Set the source to create the hash from (when using `[hash]` / `[contenthash]`).
553576

554577
The list of available keys are:
555578

@@ -588,30 +611,6 @@ preprocess: [
588611
</style>
589612
```
590613

591-
**`getLocalIdent`**
592-
593-
Customize the creation of the classname instead of relying on the built-in function.
594-
595-
```ts
596-
function getLocalIdent(
597-
context: {
598-
context: string, // the context path
599-
resourcePath: string, // path + filename
600-
},
601-
localIdentName: {
602-
template: string, // the template rule
603-
interpolatedName: string, // the built-in generated classname
604-
},
605-
className: string, // the classname string
606-
content: {
607-
markup: string, // the markup content
608-
style: string, // the style content
609-
}
610-
): string {
611-
return `your_generated_classname`;
612-
}
613-
```
614-
615614
**`includeAttributes`**
616615

617616
Add other attributes than `class` to be parsed by the preprocesser
@@ -700,6 +699,7 @@ Inspired by [webpack interpolateName](https://github.com/webpack/loader-utils#in
700699

701700
Globally replace the default svelte scoping by the cssModules scoping. As a result, the `module` attribute to `<style>` becomes unnecessary.
702701

702+
703703
```js
704704
// Preprocess config
705705
...
@@ -725,6 +725,24 @@ preprocess: [
725725
.title-erYt1 { color: blue }
726726
</style>
727727
```
728+
729+
**Beware**
730+
The enabled option will applied cssModules scoping to all imported Svelte files, even the ones coming from `node_modules`. When using a third party library, make sure the compiled version is being imported. In the case of a raw svelte file, its styling may be broken.
731+
732+
To prevent any scoping conflict, it is recommended to associate the option `useAsDefaultScoping` with `includePaths`.
733+
734+
```js
735+
// Preprocess config
736+
...
737+
preprocess: [
738+
cssModules([
739+
useAsDefaultScoping: true,
740+
includePaths: ['./src'],
741+
]),
742+
],
743+
...
744+
```
745+
728746
## Migrating from v1
729747
If you want to migrate an existing project to `v2` keeping the approach of the 1st version, follow the steps below:
730748

@@ -768,7 +786,7 @@ export default {
768786
}
769787
```
770788
771-
*Svelte Component using `<style>`*
789+
*Svelte Component*
772790
773791
```html
774792
<style module>
@@ -781,7 +799,7 @@ export default {
781799
.body {
782800
flex: 1 0 0;
783801
}
784-
button {
802+
.modal button {
785803
background-color: white;
786804
}
787805
.cancel {
@@ -801,32 +819,6 @@ export default {
801819
</section>
802820
```
803821

804-
***OR** Svelte Component importing external stylesheet*
805-
806-
```css
807-
/** style.module.css */
808-
.modal {
809-
position: fixed;
810-
}
811-
...
812-
```
813-
```html
814-
<script>
815-
import style from './style.module.css';
816-
</script>
817-
818-
<section class={style.modal}>
819-
<header class={style.wrapper}>My Modal Title</header>
820-
<div class="{style.body} {style.wrapper}">
821-
<p>Lorem ipsum dolor sit, amet consectetur.</p>
822-
</div>
823-
<footer class={style.wrapper}>
824-
<button>Ok</button>
825-
<button class={style.cancel}>Cancel</button>
826-
</footer>
827-
</section>
828-
```
829-
830822
*Final html code generated by svelte*
831823

832824
```html
@@ -840,7 +832,7 @@ export default {
840832
._1HPUBXtzNG {
841833
flex: 1 0 0;
842834
}
843-
button {
835+
._329TyLUs9c button {
844836
background-color: white;
845837
}
846838
._1xhJxRwWs7 {

0 commit comments

Comments
 (0)