不含System.config的AngularJS 2 [ng cli]中的node_modules [英] node_modules in AngularJS 2 [ng cli] without System.config

查看:74
本文介绍了不含System.config的AngularJS 2 [ng cli]中的node_modules的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 ng 生成的AngularJS 2项目中包含不包含 System.config node_modules ?

尝试(在 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"> 

项目设置:

  npm install -g angular2-cling initnpm安装npm install --save bootstrap@4.0.0-alpha.5npm开始 

注意:[默认情况下]文件树中不再有 systemjs.config.js ,也没有对 System.config 的引用…

如果我所有包含的node_modules也都被推入一个捆绑包(例如:来自 ng build -prod ),那就太好了.

解决方案

要在构建中包含诸如CSS之类的node_module资产,您需要像这样在 angular-cli.json 中列出它:

  {应用": [{样式":["../node_modules/bootstrap/dist/css/bootstrap.css"]}]} 

还可以从angular-cli自述文件中检出全局库安装

当您运行 ng build -prod 时,cli将捆绑列出的文件.

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).

解决方案

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.

这篇关于不含System.config的AngularJS 2 [ng cli]中的node_modules的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆