【问题标题】:node_modules in AngularJS 2 [ng cli] without System.configAngularJS 2 [ng cli] 中的 node_modules 没有 System.config
【发布时间】:2017-04-15 16:22:39
【问题描述】:

我如何将没有System.confignode_modules 包含在使用ng 生成的AngularJS 2 项目中?

尝试(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-cli
ng init
npm install
npm install --save bootstrap@4.0.0-alpha.5
npm start

注意:[默认情况下] 文件树中既没有 systemjs.config.js 也没有任何对 System.config 的引用......

编辑:如果我所有包含的 node_modules 也都被推送到一个包中会很棒(例如:来自ng build -prod)。

【问题讨论】:

  • 来自他们的README on github:“我们在 beta.10 和 beta.14 之间更改了构建系统,从 SystemJS 到 Webpack” - 看起来这个问题需要重新标记..跨度>
  • 完成。重新标记,包括 systemjs 仍然因为它是相关的。

标签: angular webpack systemjs node-modules angular2-cli


【解决方案1】:

要在您的构建中包含诸如 css 之类的 node_module 资产,您需要将其列在 angular-cli.json 中,如下所示:

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

还可以从 angular-cli 自述文件中查看 Global Library Installation

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

【讨论】:

  • +1 并接受:完美,有效。顺便说一句:我今天早些时候确实尝试过类似的东西,但我想我只尝试过node_modules/bootstrap/dist/css/bootstrap.css
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多