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

@gritdigital/grit-build

v1.0.0

Published

A thin wrapper around [esbuild](https://esbuild.github.io/) and [LightningCSS](https://lightningcss.dev/) to make building for the web fast and simple.

Downloads

296

Readme

GRIT Build

A thin wrapper around esbuild and LightningCSS to make building for the web fast and simple.

Features

  • Tailwind support.
  • SCSS support.
  • Manifest file generation.
  • Browsersync when gritBuild is executed with a --watch flag.
  • Accessibility testing with pa11y.
  • Lighthouse testing with lighthouse.

Getting Started

npm install @gritdigital/grit-build --save-dev

Example Usage

import gritBuild from "@gritdigital/grit-build";

gritBuild({
	build: {
		esbuild: {
			entryPoints: [
				{
					in: "./resources/ts/index.ts",
					out: "js/index",
				},
				{
					in: "./resources/styles/index.scss",
					out: "css/index",
				},
			],
			outdir: "./theme/assets",
			loader: {
				".woff2": "file",
			},
		},
		output: {
			clear: true,
			preserve: ["images"],
		},
		manifest: ["js/index.js", "css/index.css"],
	},
	dev: {
		server: {
			url: "https://example.grit",
		},
		watch: ["./theme/pages/**/*.html"],
	},
});

Regardless of where gritBuild is called, the paths should be relative to your projects root.

Interface

interface GritBuildConfig {
	/**
	 * Core build configuration
	 */
	build: {
		/** Required esbuild configuration - https://esbuild.github.io/ */
		esbuild: BuildOptions;
		/** Output directory configuration */
		output?: {
			/** Clear output directory before build */
			clear?: boolean;
			/** Patterns to ignore when clearing output directory */
			preserve?: string[];
			/** Files to remove after build completion */
			cleanup?: string[];
		};
		/** Files to include in the build manifest */
		manifest?: string[];
	};

	/**
	 * Asset management configuration
	 */
	assets?: {
		/** Directory copy operations */
		copy?: Array<{
			from: string;
			to: string;
		}>;
	};

	/**
	 * CSS processing configuration
	 */
	styles?: {
		/** Tailwind CSS configuration */
		tailwind?: {
			enabled?: boolean; // true
			config?: string;
		};
		/** LightningCSS transform options */
		lightning?: Omit<TransformOptions<CustomAtRules>, "filename" | "code">;
	};

	/**
	 * Development configuration
	 */
	dev?: {
		/** BrowserSync configuration */
		server?: {
			/** Site URL for proxying */
			url: string;
			/** BrowserSync specific options */
			options?: Exclude<browserSync.Options, "proxy">;
		};
		/** Directories to watch for changes */
		watch?: string[];
	};
}

Build Targets

JavaScript

The default esbuild target is set to the following:

  • Chrome 129
  • Firefox 129
  • Safari 15

If you need to override this, you can do so by setting the target property in the esbuild config. You can find the list of supported targets here.

gritBuild({
    build: {
        esbuild: {
            target: ["chrome129", "firefox129", "safari15"],
        },
    }
});

CSS

The default LightningCSS target is set to >= 0.25% meaning it will support browsers that make up more or equal to 0.25% of global usage.

You can override this like so:

import browserslist from "browserslist";
import { browserslistToTargets } from "lightningcss";

gritBuild({
    styles: {
        lightning: {
            targets: browserslistToTargets(browserslist(">= 0.25%"))
        }
    }
});

Plugins

Esbuild Plugins

import {
  copyDirsPlugin,
  manifestPlugin,
  clearOutdirPlugin,
  browserSyncPlugin,
  removeFilesPlugin,
} from "@gritdigital/grit-build/esbuild";

Eslint Plugin

// .eslint.config.mjs
import gritEslint from "@gritdigital/grit-build/eslint";

export default [
    ...gritEslint.configs.recommended,
]

Prettier Plugins

// .prettier.config.js

export { default } from "@gritdigital/grit-build/prettier";

// or

import prettier from "@gritdigital/grit-build/prettier";

export default {
  ...prettier,
  // your custom config
}

Helpers

getTwigImportPaths

This is a helper function for Twig and Tailwind setups that allows you to recursively find all of the twig include/embed paths for a given set of components. This is inteded to be used in conjunction with Tailwind's content property.

import { getTwigImportPaths } from "@gritdigital/grit-build/helpers";

export default {
  content: [
    "theme/**/*.html",
    ...getTwigImportPaths({
      root: "views",
      components: ["blocks/block-1.twig", "blocks/block-2.twig"],
      // aliases: {
        // "@ui/": "",
      // },
      ignoreComponents: [],
      ignoreImports: [],
    }),
  ],
  theme: {
    extend: {},
  },
  plugins: [],
};

Testing

Accessibility

npx grit-tests-accessibility --sitemap https://mysite.local/sitemap_index.xml --standard WCAG2AA --url https://mysite.local

If you provide both a sitemap and url, the url will be used as the default. Its recommended to just provide one of the two flags.

Lighthouse

npx grit-tests-lighthouse --url https://mysite.local