简体   繁体   English

NPM软件包安装到公共目录中(最佳实践)

[英]NPM package install into public directory (best practice)

Currently I am working on a website project. 目前,我正在从事一个网站项目。 Its file structure looks like below: 其文件结构如下所示:

source_code
- application
- node_modules
- system
- www
-- js
-- css
-- img
-- third-party
-- index.php
- package.json

This time I would like to ensure third-party libraries with NPM. 这次,我想确保第三方库具有NPM。

What is the best practice if some package should be available in public way and I want to avoid the manual copy-paste flow. 如果应该以公开方式提供某些软件包,并且我想避免手动复制粘贴流程,那么最佳实践是什么?
(Example packages: jquery, lazysize, bootstrap) (示例包:jquery,lazysize,bootstrap)

It depends on how you're setting things up to be used. 这取决于您如何设置要使用的东西。 If you're using webpack , for example, you would probably handle your JavaScript dependencies in package.json , and let webpack collect all these into a dist/bundle.js file which is the actual JS file included in your index.html . 例如,如果您使用的是webpack ,则可能会处理package.json的JavaScript依赖关系,并让webpack将所有这些都收集到dist/bundle.js文件中,该文件是index.html包含的实际JS文件。

If you don't have a packaging step like this set up, you can do one of these methods: 如果没有像这样设置的打包步骤,则可以执行以下方法之一:

  • Link out to a CDN in your index.html ( <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script> ) 链接到index.html中的CDN( <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
  • Download this file in www/js/lib/ and include it locally within the site ( <script src="/js/lib/jquery-3.2.1.slim.min.js"></script> ). www/js/lib/下载此文件,并将其本地包含在站点中( <script src="/js/lib/jquery-3.2.1.slim.min.js"></script> )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM