Giter Club home page Giter Club logo

postcss-inline-base64's Introduction

PostCSS Inline Base64

Node.js CI Coverage Status Snyk badge

PostCSS plugin used to replace value inside of url function to base64

Usage

See the example below

import postcssInlineBase64 from 'postcss-inline-base64'

postcss([
  postcssInlineBase64(options),
])

If you are using CommonJS module:

postcss([
  require('postcss-inline-base64')(options),
])

Options

Name Type Default Description
baseDir string process.cwd() Path to load files

Example

Use the syntax below inside url() function:

Variations:

 - b64---{file}---
 - b64---'{file}'---
 - b64---"{file}"---
 - 'b64---{file}---'
 - "b64---{file}---"

input

:root {
  --image: 'b64---./example.gif---';
}

@font-face {
  font-family: 'example';
  src: url('b64---./example.woff---') format('woff'), url('b64---./example.woff2---') format('woff2');
  font-weight: normal;
  font-style: normal;
}

body {
  background-color: gray;
  background-image: url(var(--image));
}

.notfound {
  background-image: url('b64---https://file.not/found.png---');
}

.ignore {
  background-image: url('https://cdn.lagden.in/mask.png');
}

output

:root {
  --image: 'data:image/png;charset=utf-8;base64,iVBORw0K...SuQmCC';
}

@font-face {
  font-family: 'example';
  src: url('data:font/woff;charset=utf-8;base64,d09...eLAAAA==') format('woff'), url('data:font/woff2;charset=utf-8;base64,d09...eLAAAA==') format('woff2');
  font-weight: normal;
  font-style: normal;
}

body {
  background-color: gray;
  background-image: url(var(--image));
}

.notfound {
  background-image: url('https://file.not/found.png');
}

.ignore {
  background-image: url('https://cdn.lagden.in/mask.png');
}

See PostCSS docs for examples for your environment.

Donate ❤️

License

MIT © Thiago Lagden

postcss-inline-base64's People

Contributors

dependabot[bot] avatar lagden avatar stfsy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

opengg elmacno

postcss-inline-base64's Issues

Must use import to load ES Module

Hi @lagden, wanted to check whether this breaking changes was intentional as it's not reflected in the changelog or readme.

I'm using postcss-inline-base64 as a part of my build pipeline. With the newest version the build fails with the following error:

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\workspace\...\node_modules\postcss-inline-base64\src\index.js
require() of ES modules is not supported.
require() of C:\workspace\...\node_modules\postcss-inline-base64\src\index.js from C:\workspace\...\blauspecht-frontend\postcss.config.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), 
or remove "type": "module" from C:\workspace\...\node_modules\postcss-inline-base64\package.json.

Configuration

module.exports = {
    plugins: [
        require('postcss-import'),
        require('tailwindcss'),
        require('postcss-inline-base64'),
        require('autoprefixer'),
        require('cssnano'),
        require('postcss-nested')
    ]
}

Custom CSS properties

Hi!
Thanks for a great plugin. Has been an awesome experience to work with it.
I'm struggling to make it work with a CSS variable though.
What i want is to put the generated base64 code into a CSS variable to avoid it to appear multiple times in CSS.
Something like this:

:root {
  --image-mainmenu-bg: url(b64---'img/mainmenu-bg.png'---);
}

This however doesn't work, no PostCSS transformation happens and the resulting CSS contains literal string url(b64---'img/mainmenu-bg.png'---);. I tried different syntaxes.

Is there any way this could be resolved?

Melhorias

  • Criar cache
  • Adicionar a flag g no Regex
  • Criar testes para novas features
  • Adicionar coverage

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.