size-limit
size-limit copied to clipboard
no-install, no-config options
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?
Would be primo if it worked as npx size-limit --limit="1kb" without needing any installation.
Sure, send PR
Nothing special. Maybe we can think of providing array pf paths and imports. But we can do it later.
Hey @ai, is this task still open to work in?
@diekotto yes, you can prepare and send PR
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:
- size-limit is installed globally
- The project has the appropriate plugin installed in devDependencies
- 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
-
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
-
Configuration Requirements
- The tool expects to find configuration either in:
- package.json
- .size-limit.json
- Other supported config files
- The tool expects to find configuration either in:
-
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
- Different projects need different plugins:
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.
@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 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"
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 yes, this plan looks nice (you have to install plugins first).
@ai I made a PR to clarify the npx/command line usage in the readme.