A
A
Alexander Ablizin2020-05-15 21:47:09
webpack
Alexander Ablizin, 2020-05-15 21:47:09

Vue.js is it possible to override component file from node_modules without crutches?

For example: in vue cli projects, I often use the well-known vue-select component, it is quite convenient, but it does not have what I need, namely displaying options in the form of html code and not text. I can easily change the node_modules/vue-select/src/components/Select.vue file and fix what I need, but it will be a bike crutch because you can’t just take and change the file in the node_modules folder (perhaps the universe will collapse or worse, another the update will just overwrite my work)! I honestly googled but did not find a way to simply take and redefine one file from the component so that web-pack would render it instead of the original. Please tell me what is the most righteous way to solve such a problem, there are a lot of good things in npm, but sometimes I want to do even better and I have too many crutches in my projects, thanks.
update1: With regard to vue-select specifically, my example is inappropriate, since I overlooked that it still has such an opportunity, but what about components that cannot be extended by the methods of the components themselves?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Aetae, 2020-05-18
@mcmraak

If the need is adequate - add the code, make a PR to the author and enjoy the next version.
If you have a special need, fork and either publish to npm (there are no restrictions on this) in your namespace, or simply put it in the project and link your local version through link:./pathor file:./path.
Monkey patching one specific file is not an option (although any crutches are technically possible - webpack is freely expandable with plugins), because in the next version of either, the author can completely redraw the internal structure and everything will break for you.

0
0xD34F, 2020-05-15
@0xD34F Vue.js

I use the well-known vue-select component, it is quite convenient, but it does not have what I need, namely displaying options in the form of html code and not text

Yah? So I open the documentation, and I see that this component has an option slot - you can draw such markup inside as you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question