-
Notifications
You must be signed in to change notification settings - Fork 8
/
import_cost.txt
261 lines (185 loc) · 9.89 KB
/
import_cost.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
*import_cost.txt* Display import size for JavaScript packages
_ _ _ ~
(_)_ __ ___ _ __ ___ _ __| |_ ___ ___ ___| |_ ~
| | '_ ` _ \| '_ \ / _ \| '__| __|____ / __/ _ \/ __| __|~
| | | | | | | |_) | (_) | | | ||_____| (_| (_) \__ \ |_ ~
|_|_| |_| |_| .__/ \___/|_| \__| \___\___/|___/\__|~
|_| ~
Displays the import size of the JavaScript packages you are
importing inside Vim!
==============================================================================
CONTENTS *import-cost-contents*
1. Intro ............................... |import-cost|
2. Installation ........................ |import-cost-install|
3. Commands............................. |import-cost-commands|
4. Mappings............................. |import-cost-mappings|
5. Configuration ....................... |import-cost-configuration|
6. Highlights .......................... |import-cost-highlights|
7. License ............................. |import-cost-license|
8. Contributing ........................ |import-cost-contributing|
9. Credits ............................. |import-cost-credits|
10. Changelog ........................... |import-cost-changelog|
==============================================================================
INTRO *import-cost*
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.
This plugin works for both JavaScript and TypeScript projects.
==============================================================================
INSTALLATION *import-cost-install*
You can use your typical plugin manager in order to install this plugin. Make
sure you have `node` (>= 8) and `npm` installed, as it is required for this
plugin to run.
Run the following from the root path of the plugin (the same directory
in which the file package.json is located): >
$ npm install
<
This will install the required dependencies for the plugin. You can utilize
your plugin manager's post-hook feature for this (if it is available). See the
examples below:
* https://github.com/junegunn/vim-plug >
Plug 'yardnsm/vim-import-cost', { 'do': 'npm install' }
<
==============================================================================
COMMANDS *import-cost-commands*
------------------------------------------------------------------------------
:ImportCost *:ImportCost*
Calculate the bundle size for each import in the opened buffer. When using
Neovim's virtual text feature to show the result, the results will be shown
next to the `import` statements or the `require` calls.
When using the scratch buffer, if there is only 1 result, and
|g:import_cost_always_open_split| is set to 0, the result will be shown below.
Otherwise, a new split will be opened, containing the results for each import
in the file.
This command support line ranges. By default it will act on the whole file.
------------------------------------------------------------------------------
:ImportCostSingle *:ImportCostSingle*
Calculate the bundle size for the current line only. If
|g:import_cost_always_open_split| is set to 1, a new split will be opened,
containing the result. Otherwise, the result will be shown below.
------------------------------------------------------------------------------
:ImportCostClear *:ImportCostClear*
If Nvim's virtual text feature is being used, running this command will clear
the virtual text that has been set by this plugin.
==============================================================================
MAPPINGS *import-cost-mappings*
These mappings are available in the split showing the import sizes (only when
not using Neovim's virtual text feature).
------------------------------------------------------------------------------
Show total import size *import-cost-total-size*
Bound to: s
Shows the total size of all calculated imports in the results buffer (or
range).
------------------------------------------------------------------------------
Quit *import-cost-quit*
Bound to: q
Closes the results buffer.
==============================================================================
CONFIGURATION *import-cost-configuration*
You can configure the following settings to change how this plugin works.
------------------------------------------------------------------------------
g:import_cost_show_gzipped *g:import_cost_show_gzipped*
When this option is on, the plugin will also display the gzipped size of the
import. >
let g:import_cost_show_gzipped = 1
<
Value: 0 or 1
Default: 1 (show gzipped size)
------------------------------------------------------------------------------
g:import_cost_always_open_split *g:import_cost_always_open_split*
When this option is on, the plugin will always open the output split, even if
there is only one option: >
let g:import_cost_always_open_split = 1
<
Value: 0 or 1
Default: 1 (always open a split)
This option only applies when the scratch buffer is used.
------------------------------------------------------------------------------
g:import_cost_split_size *g:import_cost_split_size*
This option controls the size of the output split. You can set this option to
0 in order to split at the default value (50%): >
let g:import_cost_split_size = 0
<
Value: number
Default: 50
This option only applies when the scratch buffer is used.
------------------------------------------------------------------------------
g:import_cost_split_pos *g:import_cost_split_pos*
This option controls where to open output window: >
let g:import_cost_split_pos = 'right'
<
Value: "left", "right"
Default: "left"
This option only applies when the scratch buffer is used.
------------------------------------------------------------------------------
g:import_cost_disable_async *g:import_cost_disable_async*
When this option is on, the imports size calculation will be run
synchronously. This is not recommended, as it will cause the UI to block until
the execution is complete.
If you are running a version without asynchronous capabilities, this option is
enabled by default. >
let g:import_cost_disable_async = 1
<
Value: 0 or 1
Default: 0 (use asynchronous execution)
------------------------------------------------------------------------------
g:import_cost_virtualtext *g:import_cost_virtualtext*
When this option is on, this plugin will use Neovim's virtual text feature to
show the results next to the `import` statements and the `require` calls,
instead of opening the scratch buffer in a split.
If you are running a version without virtualtext, this option is assumed to be
set to false.
>
let g:import_cost_virtualtext = 0
<
Value: 0 or 1
Default: 1 (use virtualtext)
------------------------------------------------------------------------------
g:import_cost_virtualtext_prefix *g:import_cost_virtualtext_prefix*
This options sets the prefix used to when displaying the results when using
the virtual text feature.
>
let g:import_cost_virtualtext_prefix = " > "
<
Value: string
Default: " > "
------------------------------------------------------------------------------
g:import_cost_slient *g:import_cost_silent*
When this option is on, the plugin does not echo error messages.
>
let g:import_cost_silent = 1
<
Value: 0 or 1
Default: 0
==============================================================================
HIGHLIGHTS *import-cost-highlights*
ImportCostVirtualText
Default: `highlight link ImportCostVirtualText NonText`
The highlight used for the virtual text displayed by this plugin (only when
virtual text is supported).
==============================================================================
LICENSE *import-cost-license*
The project is licensed under the MIT license. Copyright (c) 2018 Yarden
Sod-Moriah.
See: http://github.com/yardnsm/vim-import-cost/blob/master/LICENSE
==============================================================================
CONTRIBUTING *import-cost-contributing*
This project is hosted on GitHub. Feel free to submit issues, bug fixes and
features!
You can find the project page here:
http://github.com/yardnsm/vim-import-cost/
==============================================================================
CREDITS *import-cost-credits*
The idea is heavily inspired by Wix's "import-cost" plugin. This plugin also
utilize the "import-cost" package (also by Wix), to calculate the bundle size
for each import.
See: https://github.com/wix/import-cost
==============================================================================
CHANGELOG *import-cost-changelog*
v1.0.0
* Initial stable release.
vim:tw=78:sw=4:ft=help:norl: