size-limit icon indicating copy to clipboard operation
size-limit copied to clipboard

no-install, no-config options

Open nicholaswmin opened this issue 1 year ago • 2 comments

Hey man,

2 things:

  • Would be primo if it worked as npx size-limit --limit="1kb" without needing any installation. This was closed here #243 but it's not clear to me if you agree with the suggestion?
  • Any objection against CLI arguments? I don't see the point of configuration files for such a small API surface.

Would you accept any PRs for these? If yes, anything important I should keep aware of before I dive in?

nicholaswmin avatar Sep 07 '24 20:09 nicholaswmin

Would be primo if it worked as npx size-limit --limit="1kb" without needing any installation.

Sure, send PR

ai avatar Sep 07 '24 23:09 ai

Nothing special. Maybe we can think of providing array pf paths and imports. But we can do it later.

ai avatar Sep 07 '24 23:09 ai

Hey @ai, is this task still open to work in?

diekotto avatar Jan 02 '25 08:01 diekotto

@diekotto yes, you can prepare and send PR

ai avatar Jan 02 '25 09:01 ai

Investigation: NPX Direct Usage with size-limit

Summary

We investigated the possibility of using size-limit directly with npx without prior configuration. Our findings show that the tool is deeply integrated with its plugin system and project configuration, making direct npx usage impractical.

Current Working Setup

The tool works correctly when:

  1. size-limit is installed globally
  2. The project has the appropriate plugin installed in devDependencies
  3. The project is properly configured
# Global installation
npm install -g size-limit

# Project setup (in project directory)
npm install --save-dev @size-limit/file  # or other appropriate plugin

# Usage
size-limit --limit "10kb" dist/bundle.js

Attempted NPX Approaches

Direct NPX Usage

npx size-limit --limit "10kb" dist/bundle.js
  • Result: Fails due to missing plugin dependencies

Multiple Package Installation

npx -p size-limit -p @size-limit/file size-limit --limit "10kb" dist/bundle.js
  • Result: Installation errors due to package interdependencies

Why It Doesn't Work

  1. Plugin Architecture

    • size-limit requires at least one plugin to function
    • Plugins are determined based on project type
    • The tool includes a setup wizard to help choose appropriate plugins
  2. Configuration Requirements

    • The tool expects to find configuration either in:
      • package.json
      • .size-limit.json
      • Other supported config files
  3. Project Type Detection

    • Different projects need different plugins:
      • Applications: @size-limit/preset-app
      • Large libraries: @size-limit/preset-big-lib
      • Small libraries: @size-limit/preset-small-lib

Recommendation

Continue using the recommended installation process:

npm install --save-dev size-limit @size-limit/preset-app  # or appropriate preset

The tool is designed to be part of a project's development setup rather than a one-off utility. This ensures proper configuration and accurate size calculations based on the project's specific needs.

diekotto avatar Jan 02 '25 10:01 diekotto

@ai Looking at our investigation and findings, I recommend closing this issue. The effort required to modify size-limit for direct npx usage would require significant architectural changes to its plugin system and configuration management, while the benefit would be minimal since the tool is designed to be part of a project's development setup rather than a one-off utility.

The current design choices of size-limit - with its preset system, plugin architecture, and project-type-specific configurations - are intentional and provide value for long-term project maintenance. Creating a workaround for npx would either compromise these design principles or require maintaining additional packages, neither of which seems worth the development effort at this time.

I suggest keeping the current installation and configuration workflow as it provides the most reliable and accurate size checks for different types of projects.

diekotto avatar Jan 02 '25 10:01 diekotto

@diekotto cool research.

What do you think if we will use --limit not for global npx but for size-limit from devDependencies just to avoid having extra config. Something like:

npm add --save-dev size-limit @size-limit/esbuild
./node_modules/.bin/size-limit --limit "10Kb"

ai avatar Jan 02 '25 23:01 ai

Hi @ai, Your commands will work but it can be more simple, since the request seems to minimize the installations required. I've found that the plugin architecture is a core part of size-limit's design and I think the cleanest solution is to maintain this design by having the minimum required setup:

Install required plugin(s) as dev dependencies:

npm add --save-dev @size-limit/file # or other appropriate plugin

Using npx with local installation:

npx size-limit --limit "10Kb" dist/bundle.js

This approach maintains the tool's integrity while providing the simplicity users are looking for.

diekotto avatar Jan 03 '25 06:01 diekotto

@diekotto yes, this plan looks nice (you have to install plugins first).

ai avatar Jan 07 '25 20:01 ai

@ai I made a PR to clarify the npx/command line usage in the readme.

diekotto avatar Jan 08 '25 07:01 diekotto