使用CDN与通过NPM安装库 [英] Using CDN vs Installing library by NPM
问题描述
尽管,我一直在使用NPM,但是我不明白如何将node_modules中的文件添加到我的index.html并从那里开始工作.
Though, I have been using NPM, but I do not understand how the files in the node_modules are added to my index.html and work from there.
例如,如果我必须使用jQuery,它是如此简单.我将通过CDN获取文件并添加到我的index.html文件中
For Example, if I have to use jQuery, its so simple. I will get the file through cdn and add in my index.html file
案例I:CDN
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
</head>
<body>
<script>
$(document).ready(function(){
$('body').css('background','red');
});
</script>
</body>
</html>
现在,我不是通过cdns添加的,但是现在我将通过NPM添加jQuery.我将创建一个package.json文件,然后通过转到相应的文件夹并键入以下内容来添加jQuery:
Now, I am adding not by cdns, but I will now include jQuery by NPM. I will create a package.json file and then add jQuery by going to the respective folder and type:
案例II:NPM-node_module文件夹
我现在已经完成了以下步骤:
I have now done the followign steps:
-
由
npm init --yes
npm install jquery --save
现在,按文件夹显示如下:
Now, by folder looks like this:
现在,因为我现在已经删除了jQuery的cdn链接,所以我不知道如何将node_modules中的"jQuery文件"添加到我的index.html中?
Now, as I have now removed cdn link of jQuery, I dont know how will 'jQuery file' from node_modules will be added to my index.html?
请,有人帮忙.我不知道...我正在浏览器中执行此操作!
Please, someone help. I have no clue ...I am doing this on browser!
推荐答案
我可能误解了您的问题...但是您不能仅将此行添加到您的index.html
文件中吗?
I might have misunderstood your question... But can't you just add this line to your index.html
file?
<script src="node_modules/jquery/dist/jquery.min.js"></script>
这篇关于使用CDN与通过NPM安装库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!