• Stars
    star
    541
  • Rank 82,089 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

GitHub Action that adds compressed size changes to your PRs.

compressed-size-action

A GitHub action that reports changes in compressed file sizes on your PRs.

  • Automatically uses yarn, pnpm or npm ci when lockfiles are present
  • Builds your PR, then builds the target and compares between the two
  • Doesn't upload anything or rely on centralized storage
  • Supports custom build scripts and file patterns

Usage:

Add a workflow (.github/workflows/main.yml):

name: Compressed Size

on: [pull_request]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - uses: preactjs/compressed-size-action@v2

Customizing the Build

By default, compressed-size-action will try to build your PR by running the "build" npm script in your package.json.

If you need to perform some tasks after dependencies are installed but before building, you can use a "postinstall" npm script to do so. For example, in Lerna-based monorepo:

{
  "scripts": {
    "postinstall": "lerna bootstrap",
    "build": "lerna run build"
  }
}

It is also possible to define a "prebuild" npm script, which runs after "postinstall" but before "build".

You can also specify a completely different npm script to run instead of the default ("build"). To do this, add a build-script option to your yml workflow:

name: Compressed Size

on: [pull_request]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - uses: preactjs/compressed-size-action@v2
      with:
+       build-script: "ci"

Clean up state between builds

For repositories or custom monorepo setups where files are modified in ways that are not reset by npm ci && npm run build, it may be necessary to define a custom "clean" script. This script resets any file modifications after the upstream (target) build ends and your PR code (HEAD) is checked out, but before installation of npm dependencies for HEAD:

name: Compressed Size
on: [pull_request]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: preactjs/compressed-size-action@v2
      with:
        repo-token: "${{ secrets.GITHUB_TOKEN }}"
+       clean-script: "clean"
// package.json
{
  "scripts": {
    // example - a simple nested node_modules setup:
    "postinstall": "cd packages && npm i",
    // between the two builds, we need to delete the inner node_modules:
    "clean": "rm -rf packages/node_modules"
  }
}

Customizing the list of files

compressed-size-action defaults to tracking the size of all JavaScript files within dist/ directories - anywhere in your repository, not just at the root. You can change the list of files to be tracked and reported using the pattern and exclude options, both of which are minimatch patterns:

name: Compressed Size
on: [pull_request]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: preactjs/compressed-size-action@v2
      with:
+       pattern: "./build-output/**/*.{js,css,html,json}"
+       exclude: "{./build-output/manifest.json,**/*.map,**/node_modules/**}"

Files are collected by finding matches for pattern, then any of those that match exclude are ignored. For that reason, most projects don't need to modify exclude. The default values for pattern and exclude are as follows:

with:
  # Any JS files anywhere within a dist directory:
  pattern: "**/dist/**/*.js"

  # Always ignore SourceMaps and node_modules:
  exclude: "{**/*.map,**/node_modules/**}"

Dealing with hashed filenames

A strip-hash option was added in v2 that allows passing a custom Regular Expression pattern that will be used to remove hashes from filenames. The un-hashed filenames are used both for size comparison and display purposes.

By default, the characters matched by the regex are removed from filenames. In the example below, a filename foo.abcde.js will be converted to foo.js:

strip-hash: "\\b\\w{5}\\."

This can be customized further using parens to create submatches, which mark where a hash occurs. When a submatch is detected, it will be replaced with asterisks. This is particularly useful when mix of hashed and unhashed filenames are present. In the example below, a filename foo.abcde.chunk.js will be converted to foo.*****.chunk.js:

strip-hash: "\\.(\\w{5})\\.chunk\\.js$"

Increasing the required threshold

By default, a file that's been changed by a single byte will be reported as changed. If you'd prefer to require a certain minimum threshold for a file to be changed, you can specify minimum-change-threshold in bytes:

minimum-change-threshold: 100

In the above example, a file with a delta of less than 100 bytes will be reported as unchanged.

Compression

By default, files are compared after gzip compression, but it's possible to use other compression algorithms (gzip/brotli/none) or disable the compression.

compression: "none"

More Repositories

1

preact

⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
JavaScript
36,650
star
2

wmr

👩‍🚀 The tiny all-in-one development tool for modern web apps.
JavaScript
4,928
star
3

preact-cli

😺 Your next Preact PWA starts in 30 seconds.
JavaScript
4,685
star
4

signals

Manage state with style in every framework
TypeScript
2,105
star
5

preact-router

🌎 URL router for Preact.
JavaScript
972
star
6

preact-compat

ATTENTION: The React compatibility layer for Preact has moved to the main preact repo.
JavaScript
949
star
7

awesome-preact

A curated list of amazingly awesome things regarding Preact ecosystem 🌟
885
star
8

preact-render-to-string

📄 Universal rendering for Preact: render JSX and Preact components to HTML.
JavaScript
574
star
9

next-plugin-preact

Next.js plugin for preact X
JavaScript
391
star
10

preact-www

📖 Preact documentation website.
JavaScript
358
star
11

preact-custom-element

Wrap your component up as a custom element
JavaScript
356
star
12

prefresh

Hot Module Reloading for Preact
JavaScript
351
star
13

preact-devtools

Browser extension for inspection Preact applications
TypeScript
295
star
14

preset-vite

Preset for using Preact with the vite bundler
TypeScript
256
star
15

eslint-config-preact

Unopinionated baseline ESLint config for Preact and Preact CLI codebases.
JavaScript
85
star
16

enzyme-adapter-preact-pure

Preact adapter for the Enzyme UI testing library
TypeScript
67
star
17

preact-iso

Isomorphic utilities for Preact
JavaScript
55
star
18

preact-ssr-prepass

Drop-in replacement for react-ssr-prepass
JavaScript
47
star
19

create-preact

Create a Vite-powered Preact app in seconds
JavaScript
35
star
20

preact-integrations

A collection of sample apps demonstrating Preact's compatibility with various 3rd party libraries
JavaScript
35
star
21

rfcs

RFCs for changes and ideas in relation to Preact
30
star
22

babel-plugin-transform-replace-expressions

A Babel plugin for replacing expressions with other expressions
JavaScript
23
star
23

jest-preset-preact

Jest preset for testing Preact apps
JavaScript
19
star
24

babel-plugin-transform-rename-properties

A Babel plugin for renaming JavaScript properties
JavaScript
19
star
25

legacy-compat

React 15 compatibility layer for Preact
JavaScript
16
star
26

preact-netlify

Preact's netlify CMS template
JavaScript
15
star
27

playwright-ct

Preact adapter for Playwright Component testing
TypeScript
15
star
28

compat-alias-package

JavaScript
10
star
29

babel-plugin-transform-hook-names

Add custom hook names for devtools
TypeScript
7
star
30

migrate-preact-x

JavaScript
6
star
31

preact-cli-experiment

TypeScript
4
star
32

codesandbox-template

JavaScript
4
star
33

.github

Default community files for the PreactJS organization
3
star