0.1.0 • Published 4 years ago

image-size.macro v0.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

image-size.macro is a Babel macro that gives you the size of an image (width & height) at build time using babel-plugin-macros and image-size.

Usage

Installation

  1. Install babel-plugin-macros and the macro:
yarn add -D babel-plugin-macros image-size.macro

or

npm install --save-dev babel-plugin-macros image-size.macro
  1. Add the plugin to your Babel configuration:

.babelrc

{
  "plugins": [
    "other-plugins",
+   "macros",
  ]
}

babel.config.js

module.exports = {
  plugins: [
    ...otherPlugins,
+   'macros',
  ]
}

Example

import imageSize from 'image-size.macro'

const myImageSize = imageSize('./my-image.png')

↓ ↓ ↓ ↓ ↓ ↓

const myImageSize = { height: 20, width: 10 }

License

Licensed under the MIT License, Copyright © HiDeoo.

See LICENSE for more information.