node_modules in AngularJS 2 [ng cli] without System.config

微笑、不失礼 提交于 2019-12-24 09:57:20

问题


How do I include node_modules without System.config with AngularJS 2 projects generated with ng?

Attempts (in src/index.html):

<link rel="stylesheet" href="./node_modules/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="dist/css/bootstrap.min.css">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="bootstrap.min.css">

Project setup:

npm install -g angular2-cli
ng init
npm install
npm install --save bootstrap@4.0.0-alpha.5
npm start

Note: [by default] there is neither systemjs.config.js nor any reference to System.config in the file-tree anymore…

EDIT: Would be great if all my included node_modules are also pushed into the one bundle (e.g.: from ng build -prod).


回答1:


To include node_module assets such as css with your build, you need to list it in angular-cli.json like this:

{
  "apps": [
    {
      "styles": [
        "../node_modules/bootstrap/dist/css/bootstrap.css"
      ]
    }
  ]
}

Also checkout Global Library Installation from the angular-cli readme.

When you run ng build -prod the cli will bundle the listed files.



来源:https://stackoverflow.com/questions/40903716/node-modules-in-angularjs-2-ng-cli-without-system-config

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!