首页 > 解决方案 > 在角度项目上安装引导程序

问题描述

嗨,我的机器上有最新的 angular cli。我试图在 Angular 项目上安装引导程序。这些是我遵循的步骤。

  1. 新的演示
  2. npm install bootstrap jquery --save
  3. 然后在我复制下面代码的 angular.json 文件中的 vs code 中打开项目。

    “样式”:[“styles.css”,“../node_modules/bootstrap/dist/css/bootstrap.css”],“脚本”:[“../node_modules/jquery/dist/jquery.min.js” ,“../node_modules/bootstrap/dist/js/bootstrap.js”]

之后我运行项目 ng serve 我收到了这个错误消息。

Angular Live Development Server 正在监听 localhost:4200,在http://localhost:4200/上打开浏览器** 91% 额外的资产处理脚本-webpack-plugin× 「wdm」: Error: ENOENT: no such file or directory,打开 'D:\Angular\node_modules\jquery\dist\jquery.min.js'

标签: javascriptangularinstallationangular6

解决方案


Angular 6 及更高版本的 CLI 项目将使用 angular.json而不是.angular-cli.json用于构建和项目配置。

每个 CLI 工作区都有项目,每个项目都有目标,每个目标都可以有配置。文档

. {
  "projects": {
    "my-project-name": {
      "projectType": "application",
      "architect": {
        "build": {
          "configurations": {
            "production": {},
            "demo": {},
            "staging": {},
          }
        },
        "serve": {},
        "extract-i18n": {},
        "test": {},
      }
    },
    "my-project-name-e2e": {}
  },
}

在您的 angular.json 中,将文件路径添加到build目标下的样式和脚本数组中,./而不是../

Boostrap 4不再支持Glyphicons,您可以使用Font Awesome代替:
执行npm install --save font-awesome并将文件路径添加到样式数组

 "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/ng6",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css","./node_modules/bootstrap/dist/css/bootstrap.min.css"
               "./node_modules/font-awesome/css/font-awesome.css"
            ],
            "scripts": ["./node_modules/jquery/dist/jquery.min.js",
                       "./node_modules/bootstrap/dist/js/bootstrap.min.js"]
          },

推荐阅读