【问题标题】:Loading css files in index.html in between certain css files defined in angular cli-json在 angular cli-json 中定义的某些 css 文件之间加载 index.html 中的 css 文件
【发布时间】:2018-02-08 11:28:55
【问题描述】:

我的 index.html 中有一些来自另一个应用程序的外部样式表。

    <link href = "www.anotherapplication.com/css/anotherapp.css">

我在 angular-cli.json 中的“样式”下有应用程序特定的 css,例如

  "styles": [
    "../node_modules/foundation-sites/assets/foundation.scss",
    "my-application.scss"

  ],

假设我的应用程序的基本 css 是必须包含在“my-application.scss”之前但在“foundation.scss”之后的“anotherapp.css”。

1) 在这种情况下如何订购我的 css 文件?

2) 另外,为什么 angular-cli.json 中定义的所有 css/scss 文件在 html 页面中呈现为内部样式? (- 使得在 chrome 开发者工具中查看源代码变得困难)

谢谢!

【问题讨论】:

    标签: css angular angular-cli


    【解决方案1】:

    我猜你总是想得到当前的anotherapp.css,否则你可以把文件保存在app/legacy/css这样的文件夹中,并相应地修改styles配置。因此,要始终获得当前的anotherapp.css,您可以使用npm package download-cli 并修改一些npm scriptscli configs。这是setps:

    • npm install -g download-cli
    • 将新的 npm 脚本添加到您的 package.json download": "download --out ./src/app/legacy/css www.anotherapplication.com/css/anotherapp.css"
    • 修改你的ng serve/build/etc脚本
      "build": "npm run download &amp;&amp; ng build",
      "serve": "npm run download &amp;&amp; ng serve"
    • 修改您的 styles 配置,例如:

      "styles": [
      "../node_modules/foundation-sites/assets/foundation.scss",
      "app/legacy/css/anotherapp.css",
      "my-application.scss"
      ],

    要单独测试download 脚本,只需运行npm run download

    提示: 出于调试目的,您可以像这样命名全局样式包:

    "styles": [
        { "input": "../node_modules/foundation-sites/assets/foundation.scss", "output": "foundation" },
        { "input": "app/legacy/css/anotherapp.css", "output": "anotherapp" }
        { "input": "my-application.scss", "output": "application" }
      ],
    

    因此,这样 Angular cli 而不是只生成一个 styles.bundle.js 将生成单独的包,例如 foundation.bundle.jsanotherapp.bundle.jsapplication.bundle.js

    【讨论】:

    • 您好,感谢您的回复。但我的问题是 - 我将如何订购我的 css 文件,其中“foundation.scss”首先出现,然后“anotherapp.scss”作为第二个,然后“my-application.scss”作为第三个,其中第一个 css 文件和第三个 css 文件在 angular-cli.json 中定义,第二个 css 来自 index.html 中定义的外部 css 文件?
    • @Gsm 我想我为你想出了解决方案,只需检查更新的答案。
    • 非常感谢!所以,我做了你提到的所有步骤,但只是一个快速的问题来确认:U 的意思是“当前”anotherapp.css - 这是否意味着我的 app/legacy/css 中的 anotherapp.css 将在何时自动更新网站的外部 css 文件中有更新吗?即,每当我运行 ng serve 时?
    猜你喜欢
    • 2017-12-26
    • 2019-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-30
    • 2017-10-30
    • 2018-04-15
    • 1970-01-01
    相关资源
    最近更新 更多