# babel-plugin-asset-loader

> Help to load your asset using babel

Latest version **0.1.3** (published 2019-04-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install babel-plugin-asset-loader
pnpm add babel-plugin-asset-loader
yarn add babel-plugin-asset-loader
bun add babel-plugin-asset-loader
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2019-04-04 |
| First published | 2019-04-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 10.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Stevan Leonardy |
| Maintainers | stevan11leonardy |
| Keywords | nextjs, babel, import, loader, static, images, cdn, sse, isomorphic |

## Links

- npm: https://www.npmjs.com/package/babel-plugin-asset-loader
- Repository: https://github.com/stevan11leonardy/babel-plugin-asset-loader
- Homepage: https://github.com/stevan11leonardy/babel-plugin-asset-loader.git#readme
- Issues: https://github.com/stevan11leonardy/babel-plugin-asset-loader/issues
- npm.io page: https://npm.io/package/babel-plugin-asset-loader

## Dependencies (3)

- [mime](https://npm.io/package/mime.md) ^2.0.3
- [big.js](https://npm.io/package/big.js.md) ^5.0.3
- [fs-extra](https://npm.io/package/fs-extra.md) ^4.0.2

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.1.3 (latest) — 2019-04-04
- 0.1.2 — 2019-04-04
- 0.1.1 — 2019-04-04

## README

# babel-plugin-asset-loader

## Installation

```
npm install babel-plugin-asset-loader --save
```

```
yarn add babel-plugin-asset-loader
```

Then put following "asset-loader" as plugin in .babelrc:

```json
{
  "plugins": ["asset-loader"]
}
```

This is equivalent to following default configuration:

```json
{
  "plugins": [
    [
      "asset-loader",
      {
        "name": "[hash].[ext]",
        "extensions": ["png", "jpg", "jpeg", "gif", "svg"],
        "outputPath": "/public",
        "context": "",
        "limit": 0
      }
    ]
  ]
}
```

## Feature
This will import your asset into your package using babel and feel free to use your asset.

## How it works

More or less as follows:

1. Processes only `import` and `require` that reference files ending with one of `"extensions"`
2. Calculates actual `$name` of resource by substituting placeholders in `"name"`
3. Copies resource into `$ROOT/$outputPath/$name` where `$ROOT` is `.babelrc` location.
3. Replaces `import` and `require` in code with `"$publicPath/$name"` string



## Options

### outputPath

Tells where to put static files. By default it's `"/public"`.

This path is relative to the root of project. Setting value `null` prevents the plugin to copy the file.

### name

The default is `[hash].[ext]` where:

|Name|Type|Default|Description|
|:--:|:--:|:-----:|:----------|
|**`[ext]`**|`{String}`|`file.extname`|The extension of the resource|
|**`[name]`**|`{String}`|`file.basename`|The basename of the resource|
|**`[path]`**|`{String}`|`file.dirname`|The path of the resource relative to the `context`|
|**`[hash]`**|`{String}`|`md5`|The hash of the content, see below for more info|

The full format `[hash]` is: `[<hashType>:hash:<digestType>:<length>]`, where:

|Name|Type|Default|Description|
|:--:|:--:|:-----:|:----------|
|**`hashType`**|`{String}`|`md5`|`sha1`, `md5`, `sha256`, `sha512`|
|**`digestType`**|`{String}`|`base64`|`hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64`|
|**`length`**|`{Number}`|`128`|The length in chars|

For example: `[md5:hash:base58:8]` or `[hash:base36]`.

### extensions

List of extension asset-loader should look for in imports. All other imports are ignored.

### context

Path to directory relative to `.babelrc` where application source resides. By default `""`, but can be e.g. `"/src"`.

### limit

Value in byte to determine if the content is base64 inlined. In that case, the file is not copy to `outputPath`. It replicates [url-loader](https://github.com/webpack-contrib/url-loader) webpack loader behaviour.

Default is 0 which means nothing is inlined.

## License

[MIT](./LICENSE)

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