使用 Angular-CLI 安装第 3 方应用程序

2024-03-02

我是 angular-cli 的新手。我想安装 npm 库 mdbootstrap。我按照这里的说明进行操作:Angular CLI 说明 https://github.com/angular/angular-cli#global-library-installation

具体来说,我是这样做的:

  1. 我通过安装 mdbootstrapnpm install bootstrap.
  2. 我添加了所有文件dist目录到我的angular-cli.json.

angular-cli.json补充:

"styles": [
  "../node_modules/mdbootstrap/css/bootstrap.min.css",
  "../node_modules/mdbootstrap/css/mdb.min.css",
  "../node_modules/mdbootstrap/css/style.css"
],
"scripts": [
  "/node_modules/mdbootstrap/dist/js/bootstrap.min.js",
  "/node_modules/mdbootstrap/dist/js/jquery-3.1.1.min.js",
  "/node_modules/mdbootstrap/dist/js/mdb.min.js",
  "/node_modules/mdbootstrap/dist/js/tether.min.js",
],

我的问题:我是否还必须通过脚本包含所有这些文件<link> and <script>标签,到index.html基础文件?

EDIT

在以正确的方式进行操作之前,我只是以旧的方式安装了我的库,直接注入到index.html中。

按照上述说明操作后,我确实在 index.html 的源代码中看到了额外的插入。所以,这是有希望的。

但是,当我删除所有原始内容和手动放入index.html 文件中的标签时,一切都会崩溃。我尝试在 Chrome 调试控制台中进行 jquery 选择,但失败了。我尝试在 angular-cli 捆绑文件中搜索第三方函数。就好像 ngserve 命令没有安装任何东西一样。


不,您不需要再次包含它们。 Angular CLI 通过 webpack 为您创建这些文件。当你跑步时ng serve查看您的页面源。你会看到有一些JS文件附加到你的index.html。这些是 Angular-cli.json 中包含的 JS/CSS 文件。

例如:

scripts.bundle.js
styles.bundle.js

当你跑步时ng build这些文件由 webpack 捆绑并放置到 dist 目录中。这些是您在生产中运行时要指向的文件。

对编辑的回应:

Try ../node_modules代替/node_modules为您的脚本。另外,请确保首先加载 JQuery。

-Change-

"/node_modules/mdbootstrap/dist/js/bootstrap.min.js",
"/node_modules/mdbootstrap/dist/js/jquery-3.1.1.min.js",

-to-

"../node_modules/mdbootstrap/dist/js/jquery-3.1.1.min.js",
"../node_modules/mdbootstrap/dist/js/bootstrap.min.js",
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 Angular-CLI 安装第 3 方应用程序 的相关文章

随机推荐