npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lightningtv/vite-hex-transform

v1.1.0

Published

Converts hex colors to 0xRRGGBBAA format

Downloads

464

Readme

Vite Plugin: Hex Color Transform

Overview

The hexColorTransform plugin for Vite transforms "#RRGGBB", "#RGB", "#RRGGBBAA", and "#RGBA" into 0xRRGGBBAA format and handling optional alpha values correctly. This documentation provides instructions for configuring the plugin with include and exclude filters.

Removing hexColor

If you were using hexColor, you can find and replace all instances with:

Use VSCode to remove hexColor

hexColor\("(#[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})"\)
"$1"

Additionally, Enable default color decorators in VScode in your settings (Command + , to search for the setting) to get built in color highlighting

Installation

npm i @lightningtv/vite-hex-transform -D

Usage

Plugin Configuration

Create or update the vite.config.js file in your Vite project to include the hexColorTransform plugin with options for including and excluding files.

// vite.config.js
import { defineConfig } from 'vite';
import hexColorTransform from './hexColorTransform';

export default defineConfig({
  plugins: [
    hexColorTransform({
      include: '**/*.js', // Include all JavaScript files
      exclude: 'node_modules/**', // Exclude files in node_modules directory
    }), // Register your custom plugin with options
  ],
});

Plugin Options

The hexColorTransform plugin accepts an options object with the following properties:

  • include: A glob pattern or an array of glob patterns specifying which files to include. The default is to include all files.
  • exclude: A glob pattern or an array of glob patterns specifying which files to exclude. The default is to exclude no files.

Example

Here are some examples of how to use the include and exclude options:

// vite.config.js
import { defineConfig } from 'vite';
import hexColorTransform from './hexColorTransform';

export default defineConfig({
  plugins: [
    // Include all JavaScript files and exclude files in node_modules directory
    hexColorTransform({
      include: '**/*.js',
      exclude: 'node_modules/**',
    }),

    // Include only specific files
    hexColorTransform({
      include: ['src/**/*.js', 'src/**/*.ts'], // Include JavaScript and TypeScript files in the src directory
      exclude: 'src/ignore-this-directory/**', // Exclude a specific directory
    }),
  ],
});

How It Works

Example Code Transformation

Before

const color = "#f6f6f6";
const shortColor = '#fff';
const alphaColor = "#f6f6f680";

After

const color = 0xF6F6F6FF;
const shortColor = 0xFFFFFFFF;
const alphaColor = 0xF6F6F680;

Conclusion

The hexColorTransform plugin for Vite provides a convenient way to transform hex color strings in your code. By configuring include and exclude patterns, you can control which files are processed by the plugin, making it flexible and easy to use in various project setups.

For more information and advanced configuration options, refer to the official Vite documentation and the plugin source code.