# babel-plugin-transform-picture-imports

> Babel plugin for transforming picture import into variable contains src and srcSet

Latest version **1.0.2** (published 2017-08-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install babel-plugin-transform-picture-imports
pnpm add babel-plugin-transform-picture-imports
yarn add babel-plugin-transform-picture-imports
bun add babel-plugin-transform-picture-imports
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2017-08-01 |
| First published | 2017-08-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Pavel Ivanov |
| Maintainers | grammka |
| Keywords | picture, import, src, srcSet, 2x, 3x, plugin |

## Links

- npm: https://www.npmjs.com/package/babel-plugin-transform-picture-imports
- Repository: https://github.com/pavelivanov/babel-plugin-picture-import-replacer
- Homepage: https://github.com/pavelivanov/babel-plugin-picture-import-replacer#readme
- Issues: https://github.com/pavelivanov/babel-plugin-picture-import-replacer/issues
- npm.io page: https://npm.io/package/babel-plugin-transform-picture-imports

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2017-08-01
- 1.0.1 — 2017-08-01
- 1.0.0 — 2017-08-01

## README

# babel-plugin-transform-picture-imports

Babel plugin for transforming picture imports into variable contains 2x, 3x sizes

**Transforms**

```javascript
// picture x2
import logo from './images/logo.png'
// picture x2 x3
import icon from './images/icon.png'
```

**to** 

```javascript
const logo = (() => {
  const imagePath = "./images/logo.png";
  let src2x = "";
  let src3x = "";
  let srcSet = "";
  const src = require(imagePath);
  src2x = require(imagePath.replace(new RegExp("(.[a-z]+)$"), `@2x$1`));
  srcSet = src;

  if (src2x)
    srcSet += `, ${src2x}`;

  if (src3x)
    srcSet += `, ${src3x}`;

  return {
    src,
    srcSet
  };
})();

const icon = (() => {
  const imagePath = "./images/icon.png";
  let src2x = "";
  let src3x = "";
  let srcSet = "";
  const src = require(imagePath);
  src2x = require(imagePath.replace(new RegExp("(.[a-z]+)$"), `@2x$1`));
  src3x = require(imagePath.replace(new RegExp("(.[a-z]+)$"), `@3x$1`));
  srcSet = src;

  if (src2x)
    srcSet += `, ${src2x}`;

  if (src3x)
    srcSet += `, ${src3x}`;

  return {
    src,
    srcSet
  };
})();
```

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