How to handle installed NPM libraries from web pages and templates?

I installed, say jQuery:

npm install jquery

My site now has

ROOT/node_modules/jquery/*

subdirectory.

What to do next? Just write

<script src="/node_modules/jquery/src/jquery.js"></script>

Or can I do something to take jquery.jsfrom this path and / or encode the link in some portable way?

For example, suppose I use the Jade template. Shoud I write simply

script(src="/node_modules/jquery/src/jquery.js")
+4
source share
4 answers

To answer your question in the near future: yes, you can copy jquery.jsand transfer it to any desired folder. Then you have to change the src attribute in the script element, for example:

<script src="/new/path/jquery.js"></script>

, , js , , :

<script src="/path/libs.js"></script>

libs.js .

+1

: , ,

<script src="/node_modules/jquery/src/jquery.js"></script>

NPM, .

  • . git ( ). , .
  • . , , npm install .
  • . , , nom .

, .

  • , . .
  • Howwver, , , gulp -, .
  • , js, bundle.js. , - , vendor.bundle.js, - . vendor.bundle.js. jQuery. , , js, , .
+1

- , , . , - , , , . , , , webpack, gulp , . Webpack , :

  • js css , typescript sass
  • dev
  • js

. , .

, , ,

0

Dear, what kind of dependencies that you accept inside the node project should be in Node_Modules, and you must specify the dependency path of Node_Module / dependency_path, it will be better in project development and in Production.May it will be useful for you

0
source

Source: https://habr.com/ru/post/1679229/


All Articles