# svelte-html-asset-preprocessor

> Transform html asset relative path. Works with snowpack & webpack 5.

Latest version **0.1.3** (published 2020-12-03) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install svelte-html-asset-preprocessor
pnpm add svelte-html-asset-preprocessor
yarn add svelte-html-asset-preprocessor
bun add svelte-html-asset-preprocessor
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2020-12-03 |
| First published | 2020-10-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Jiang Fengming |
| Maintainers | jiangfengming |
| Keywords | svelte, preprocessor |

## Links

- npm: https://www.npmjs.com/package/svelte-html-asset-preprocessor
- Repository: https://github.com/jiangfengming/svelte-html-asset-preprocessor
- Homepage: https://github.com/jiangfengming/svelte-html-asset-preprocessor#readme
- Issues: https://github.com/jiangfengming/svelte-html-asset-preprocessor/issues
- npm.io page: https://npm.io/package/svelte-html-asset-preprocessor

## Recent versions

- 0.1.3 (latest) — 2020-12-03
- 0.1.2 — 2020-11-05
- 0.1.1 — 2020-11-02
- 0.1.0 — 2020-10-29

## README

# svelte-html-asset-preprocessor
Transform html asset relative path. It works with snowpack & webpack 5.

e.g.

before:
```html
<img src="foo.png">
```

after:
```html
<img src="{new URL('foo.png', import.meta.url)}">
```

## Usage
svelte.config.js:

```js
const htmlAssetPreprocessor = require('svelte-html-asset-preprocessor');

module.exports = {
  preprocess: [
    htmlAssetPreprocessor()
  ]
};
```

## Options

```js
htmlAssetPreprocessor({ rules, filter })
```

### rules
`Array`. Add custom rules. Build-in rules:

```js
const defaultRules = [
  {
    tag: 'img',
    attribute: 'src',
    type: 'src'
  },

  {
    tag: 'img',
    attribute: 'srcset',
    type: 'srcset'
  },

  {
    tag: 'input',
    attribute: 'src',
    type: 'src'
  },

  {
    tag: 'audio',
    attribute: 'src',
    type: 'src'
  },

  {
    tag: 'video',
    attribute: 'src',
    type: 'src'
  },

  {
    tag: 'video',
    attribute: 'poster',
    type: 'src'
  },

  {
    tag: 'source',
    attribute: 'src',
    type: 'src'
  },

  {
    tag: 'source',
    attribute: 'srcset',
    type: 'srcset'
  },

  {
    tag: 'track',
    attribute: 'src',
    type: 'src'
  },

  {
    tag: 'link',
    attribute: 'href',
    type: 'src'
  },

  {
    tag: 'object',
    attribute: 'data',
    type: 'src'
  },

  {
    tag: 'embed',
    attribute: 'src',
    type: 'src'
  }
];
```

### filter

```js
filter(path) -> Boolean
```

Filter the path. Return `true` to transform, or return `false` to skip the path.


## Transform css url()
Use https://github.com/canadaduane/snowpack-plugin-relative-css-urls

## License
[MIT](LICENSE)

---
_Source: https://npm.io/package/svelte-html-asset-preprocessor · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
