Webpack / Angular不发送bootstrap到dist文件夹

时间:2017-06-16 14:45:48

标签: angularjs node.js npm webpack

我正在试图弄清楚如何让一切顺利。问题是bootstrap没有出现在索引页面的dist版本中。

我不是100%肯定,但.angular-cli.json是我认为创建webpack的东西。这是文件:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "version": "1.0.0-beta.31",
    "name": "webui"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.json",
      "prefix": "app",
      "styles": [
        "styles.css",
        "../node_modules/bootstrap/dist/css/bootstrap.min.css"
      ],
      "scripts": [
        "../node_modules/jquery/dist/jquery.min.js",
        "../node_modules/bootstrap/dist/js/bootstrap.min.js"
      ],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [
    {
      "files": "src/**/*.ts",
      "project": "src/tsconfig.json"
    },
    {
      "files": "e2e/**/*.ts",
      "project": "e2e/tsconfig.json"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "css",
    "prefixInterfaces": false,
    "inline": {
      "style": false,
      "template": false
    },
    "spec": {
      "class": false,
      "component": true,
      "directive": true,
      "module": false,
      "pipe": true,
      "service": true
    }
  }
}

当我运行应用程序时,这是我在控制台中遇到的错误:

Uncaught Error: Bootstrap tooltips require Tether (http://tether.io/)
    at eval (eval at webpackJsonp.../../../../script-loader/addScript.js.module.exports (addScript.js:9), <anonymous>:7:3482)
    at eval (eval at webpackJsonp.../../../../script-loader/addScript.js.module.exports (addScript.js:9), <anonymous>:7:12271)
    at eval (eval at webpackJsonp.../../../../script-loader/addScript.js.module.exports (addScript.js:9), <anonymous>:7:14333)
    at eval (<anonymous>)
    at webpackJsonp.../../../../script-loader/addScript.js.module.exports (addScript.js:9)
    at Object.../../../../script-loader/index.js!../../../../bootstrap/dist/js/bootstrap.min.js (bootstrap.min.js?e084:1)
    at __webpack_require__ (bootstrap f1e578d…:54)
    at Object.3 (scripts.bundle.js:52)
    at __webpack_require__ (bootstrap f1e578d…:54)
    at webpackJsonpCallback (bootstrap f1e578d…:25)
(anonymous) @ VM738:7
(anonymous) @ VM738:7
(anonymous) @ VM738:7
webpackJsonp.../../../../script-loader/addScript.js.module.exports @ addScript.js:9
../../../../script-loader/index.js!../../../../bootstrap/dist/js/bootstrap.min.js @ bootstrap.min.js?e084:1
__webpack_require__ @ bootstrap f1e578d…:54
3 @ scripts.bundle.js:52
__webpack_require__ @ bootstrap f1e578d…:54
webpackJsonpCallback @ bootstrap f1e578d…:25
(anonymous) @ scripts.bundle.js:1
vendor.bundle.js:55378 Angular is running in the development mode. Call enableProdMode() to enable the production mode.

注意,它没有提到系绳文件,但这不会导致这个问题吗?不确定为什么bootstrap没有连接到dist

1 个答案:

答案 0 :(得分:1)

您是否尝试过安装并包括系绳?

安装时使用:npm i tether --save

并添加到angular-cli.json的scriptsstyles部分

  styles": [
    "styles.css",
    "../node_modules/tether/dist/css/tether.min.css",
    "../node_modules/bootstrap/dist/css/bootstrap.min.css"
  ],
  "scripts": [
    "../node_modules/jquery/dist/jquery.min.js",
    "../node_modules/tether/dist/js/tether.min.js",
    "../node_modules/bootstrap/dist/js/bootstrap.min.js"
  ],