# autobg.macro

> a babel macro which can auto-generate background-image, width, height CSS code based on the given image path, usually used with `styled-components`

Latest version **1.0.6** (published 2020-12-28) · ISC license · 0 weekly downloads

## Install

```sh
npm install autobg.macro
pnpm add autobg.macro
yarn add autobg.macro
bun add autobg.macro
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2020-12-28 |
| First published | 2020-09-09 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 4.6 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | littlee |
| Maintainers | littlee |
| Keywords | babel-plugin-macros, styled-components |

## Links

- npm: https://www.npmjs.com/package/autobg.macro
- Repository: https://github.com/littlee/autobg.macro
- Homepage: https://github.com/littlee/autobg.macro#readme
- Issues: https://github.com/littlee/autobg.macro/issues
- npm.io page: https://npm.io/package/autobg.macro

## Dependencies (2)

- [image-size](https://npm.io/package/image-size.md) ^0.9.1
- [babel-plugin-macros](https://npm.io/package/babel-plugin-macros.md) ^2.8.0

## 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

- 1.0.6 (latest) — 2020-12-28
- 1.0.5 — 2020-11-11
- 1.0.4 — 2020-10-27
- 1.0.3 — 2020-10-26
- 1.0.2 — 2020-09-10
- 1.0.1 — 2020-09-09
- 1.0.0 — 2020-09-09

## README

# autobg.macro

a babel macro which can auto-generate background-image, width (in vw), height (in vw) CSS code based on the given image path, usually used with `styled-components`

## Install

```bash
npm i -S autobg.macro
```

## Usage

```js
import styled from 'styled-components/macro';
import autobg from 'autobg.macro';

const MyDiv = styled.div`
  text-align: center;
  ${autobg('./path/to/img.png')}
  color: red;
`;
```

assuming the image file's dimension is 750x750, the code above with be compiled to

```js
import styled from 'styled-components/macro';

const MyDiv = styled.div`
  text-align: center;
  background-image: url('${require('./path/to/img.png')?.default}');
  background-size: 100%;
  background-repeat: no-repeat;
  width: 100vw;
  height: 100vw;
  color: red;
`;
```

## Config

- baseUrl (String): image path resolving base URL, default `"./src"`
- vwBase (Number): px to vw transform base value, default `750`
- esModule (Boolean): set this the same value as `url-loader` or `file-loader`, default: `true`
  - use `false` when using `react-scripts < 4`

example config using `babelMacros` field in `package.json` file, for more config detail, see https://github.com/kentcdodds/babel-plugin-macros/blob/master/other/docs/user.md#config

```json
{
  "babelMacros": {
    "autobg": {
      "baseUrl": "./src",
      "vwBase": 750,
      "esModule": true
    }
  }
}
```

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