svelte-prefix-loader
The plugin svelte-prefix-loader
allows you to specify the directory from which you want to autoload the components, depending on the prefixes in the tag name.
Install
npm install --save-dev svelte-prefix-loader
or
npm i -D headmad/svelte-prefix-loader
Usage
// rollup.config.js // Other imports const prefixLoaderConfig = App: './[prefix]/[block]/[block][-elem].svelte' My: myHandler moduleexports = ... plugins: ...
- In path template, you can use PascalCase lettering. For example:
<MyHeaderLogo />
./[prefix]/[block][-elem].svelte => ./my/header-logo.svelte
./[Prefix]/[Block][Elem].svelte => ./My/HeaderLogo.svelte
- In square brackets, you can use any simbols before keyword (prefix, block, elem). For example:
<MyHeaderLogo />
./[prefix]/[block][__elem].svelte => ./my/header__logo.svelte
- If tag has no
Block
orElem
section, template just skip they in result. For example:
./bem/[block][/__elem][/block][__elem].svelte
<MyHeader /> => ./bem/header/header.svelte
<MyHeaderLogo /> => ./bem/header/__logo/header__logo.svelte
Also
As a path you can specify a function that should return string - path to svelte-file
The sample code of the handler function:
//myHandler.jsconst path = module { return path}
Parameters
- rootDir
String
. Path to dir of root svelte-file (App.svelte) - prefix
String
. First word in tagName. Exemple, in tag<AppPageHeader />
, prefix is "App" - block
String
. Second word in tagName. Exemple, in tag<AppPageHeader />
, block is "Page" - elem
String
. Third word in tagName. Exemple, in tag<AppPageHeader />
, elem is "Header"