GithubHelp home page GithubHelp logo

isabella232 / vim-import-cost Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lumakernel/vim-import-cost

0.0 0.0 0.0 1.33 MB

๐Ÿ‹๏ธโ€โ™‚๏ธ Display the import size of the JavaScript packages in Vim!

Vim Script 92.50% JavaScript 7.50%

vim-import-cost's Introduction

vim-import-cost

Build Status

This plugin is a (very rough) port of the import-cost plugin for Visual Studio Code. In a nutshell, it calculates the bundle size for each import statement or require calls. Thanks to Neovim's virtual text feature, this plugin can show the calculated size next to the import statements, with a fallback to showing the calculated size in a scratch buffer.

This plugin exposes commands that allows you to calculate the package's size on demand. By default it'll try to use Neovim's virtual text feature.

This plugin uses the import-cost module (also part of the original import-cost plugin) that uses webpack to calculate the size of the imported module.

You can find more information about how the size calculation process works in this blog post.

Installation

Use your favorite plugin manager to install this plugin. Make sure to have node (>= 8) and npm both installed and available in your $PATH.

Using vim-plug:

Plug 'yardnsm/vim-import-cost', { 'do': 'npm install' }

If you're installing the plugin in different way, make sure to run npm install in the root path of the plugin directory, so the required dependencies will be installed.

Usage

You can initiate the plugin by demand; it does not offer any automatic calculation out of the box.

  • Use the :ImportCost command when inside a JavaScript / TypeScript buffer. This commands also support ranges, so you can initiate it from VISUAL mode.
  • Use the :ImportCostSingle command if you wish to process the current line only.
  • Use the :ImportCostClear command to clear the virtual text set by the plugin.

Configuration

Find the available configuration methods in the plugin's help file.

:help import_cost

FAQ

How can I automatically run this plugin on buffer updates?

You can all the :ImportCost command within an autocmd, so it can be triggered when the buffer is updated. This is not recommended to use when the virtual text feature is not supported.

" Put this in your .vimrc
augroup import_cost_auto_run
  autocmd!
  autocmd InsertLeave *.js,*.jsx,*.ts,*.tsx ImportCost
  autocmd BufEnter *.js,*.jsx,*.ts,*.tsx ImportCost
  autocmd CursorHold *.js,*.jsx,*.ts,*.tsx ImportCost
augroup END

License

MIT ยฉ Yarden Sod-Moriah

vim-import-cost's People

Contributors

yardnsm avatar meain avatar bary12 avatar txhawks avatar city41 avatar weirongxu avatar a avatar wsdjeg avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.