是否必须使用 npm 模块?

Is it mandatory to use npm modules?

我是 Node.js 的新手,正在尝试了解节点功能。现在我正在开发一个 Angular 2 项目,我可以在其中看到每个插件都是从 node_modules 文件夹导入的。

我的问题是,是否必须从 node_modules 导入所有内容?如果我要使用 CDN link 怎么办?

例如,如果我想使用 datatable 并且我有其 CDN (https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js) 的 links 而不是使用 from node_modules.

不,不是,但据我所知,如果您的 index.html 中有大量导入,它会影响应用的性能。而且,看起来很乱。

当然可以。但是...

Why modules?

Using a technique called "Tree shaking" your bundler can run static analysis on your code dependencies and create a bundle that only includes referenced modules. This can drastically reduce the bundle size.

Tree shaking

Tree Shaking is an optimized way of creating application bundles. The idea is to create a bundle that only includes code that is directly used by the application. Unused modules will be excluded from the final bundle. As a result we may end up with a drastically smaller application bundle.

Shorthand: 主要有 一个 重要的事情要记住:你应该只使用你将要使用的代码部分。多亏了模块,你才能做到,也许现在看起来不太清楚,但它会随着你技能的增长。