Code Monkey home page Code Monkey logo

postcss-color-hex-alpha's Introduction

⚠️ PostCSS Color Hex Alpha was moved to @csstools/postcss-plugins. ⚠️
Read the announcement

PostCSS Color Hex Alpha PostCSS

NPM Version CSS Standard Status Build Status Support Chat

PostCSS Color Hex Alpha lets you use 4 & 8 character hex color notation in CSS, following the CSS Color Module specification.

'Can I use' table

body {
  background: #9d9c;
}

/* becomes */

body {
  background: rgba(153, 221, 153, 0.8);
}

Usage

Add PostCSS Color Hex Alpha to your project:

npm install postcss-color-hex-alpha --save-dev

Use PostCSS Color Hex Alpha to process your CSS:

const postcss = require('postcss');
const postcssColorHexAlpha = require('postcss-color-hex-alpha');

postcss([
  postcssColorHexAlpha(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);

PostCSS Color Hex Alpha runs in all Node environments, with special instructions for:

Node PostCSS CLI Webpack Create React App Gulp Grunt

Options

preserve

The preserve option determines whether 4 & 8 character hex color notation should be preserved in their original form. By default, these are not preserved.

postcssColorHexAlpha({
  preserve: true
});
body {
  background: #9d9c;
}

/* becomes */

body {
  background: rgba(153, 221, 153, 0.8);
  background: #9d9c;
}

postcss-color-hex-alpha's People

Contributors

ai avatar antonio-laguna avatar fastner avatar goto-bus-stop avatar jednano avatar jonathantneal avatar moox avatar pascalduez avatar semigradsky avatar trysound 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  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

postcss-color-hex-alpha's Issues

Prevent hexa conversion within a url()

A url() containing something that looks like a hexa is getting transpiled. In this case, it’s a hash from an svg web font.

url("Fonts/e4d5b881-6835-45b7-8766-3e5b9e7cab8b.svg#e4d5b881-6835-45b7-8766-4e5b9e7cab7c") format("svg");
url("Fonts/e4d5b881-6835-45b7-8766-3e5b9e7cab8b.svgrgba(228,213,184,.50588)-6835-45b7-8766-4e5b9e7cab7c") format("svg");

See: MoOx/postcss-cssnext#339 reported by @luangjokaj

Use PostCSS 4.1 API

PostCSS Plugin Guidelines are mandatory right now. Because all of rules are about ecosystem health.

.mjs format is causing issues with .js files

I am having the following issue:

Plugin Error: Cannot find module 'C:\Users\<user>\AppData\Roaming\npm\node_modules\postcss-color-hex-alpha\node_modules\postcss-values-parser\lib\nodes\Punctuation' imported from C:\Users\<user>\AppData\Roaming\npm\node_modules\postcss-color-hex-alpha\dist\index.mjs

Generally it is caused because you are using .mjs file format, so when importing Punctuation (and all similars) is required to defines it entiry like Punctuaction.js.

It affects 8.0, but works fine at 7.0.

postcss-values-parser vulnerability

npm-audit

The above npm audit shows when I install postcss-color-hex-alpha@6 so I had to downgrade to v5, it still works but it would be good if I could use the latest version without fear of vulnerabilities.

Searching a bit, it seems postcss-values-parser@3 is the cause and updating it to v4 would fix the issue.

Thanks.

Infinite loop with Bootstrap 3

I think the issue is with postcss-color-hex-alpha so that's why I open an issue here.

Here is a reproduction. It's an Ember.js project but that shouldn't matter - it was just easier for me to reproduce. git clone https://github.com/boris-petrov/ember-cli-postcss-bug.git, cd ember-cli-postcss-bug, npm install, ./frontend/node_modules/.bin/ember serve. That would lead to an infinite loop (you'll have to kill the process by killall -9 node). Postcss' options are in the ember-cli-build.js file. Commenting-out the usage of postcss-color-hex-alpha in it will fix the issue. Also, commenting-out the importing of Bootstrap (in app/styles/app.scss which is the main entry point for the app) also resolves it.

Not sure why that is, perhaps postcss-color-hex-alpha doesn't like something in Bootstrap 3 as Bootstrap 5 works.

Not working with scss variable in production

While using postcss-preset-env I get the following results:

color: #{$black}de;

In development it will return the expected:

color: rgba(0, 0, 0, 0.87059);

But in production:

color: #000de;

In package.json I have the following scripts:

"dev": "cross-env webpack-dev-server --config webpack.config.js --mode=development -w --hot",
"prod": "cross-env webpack --config webpack.config.js --mode=production -p"

And in webpack.config.js

{
	test: /\.(sa|sc|c)ss$/,
	exclude: ['/node_modules', './dist', '/src/js', '/docs'],
	use: [
		MiniCSSExtractPlugin.loader,
		{
			loader: 'css-loader',
			options: {
				sourceMap: true,
				minimize: process.env.NODE_ENV === 'production',
			}
		},
		{
			loader: 'postcss-loader',
			options: {
				sourceMap: true,
				syntax: postCssScss,
				plugins: () => [
					autoprefixer,
					postCssPresetEnv({
						stage: 0,
						features: {
							'color-mod-function': true,
							'alpha-hex-colors': true
						}
					}),
				],
			},
		},
		{
		loader: 'sass-loader',
			options: {
				sourceMap: true
			}
		}
	]
}

I have tried to use it without the features part that didn't work. Also tried to require the color-mod-function and alpha-hex-colors as seperate package after the autoprefixer which also didn't work.

So how can I get the same output from development in production?

Support PostCSS 5.x API

This will require a major version bump so it doesn't break people who are running plugins on the 4.x path.

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.