如何在 angular 8 库中包含 SASS 样式 [英] How to include SASS styles in an angular 8 library

查看:27
本文介绍了如何在 angular 8 库中包含 SASS 样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 angular 库,用于在两个项目之间共享一些组件、指令等.

I had an angular library for sharing some components, directives and more between two projects.

最近我尝试在库中包含一些样式以在两个项目中重用,但我可以实现将其包含在包中.

Recently I tried to include in the library some styles to reuse in the two projects but I can achieve to ng build include it in the bundle.

¿有什么线索吗?

推荐答案

到目前为止,我发现的唯一方法是在打包 .tgz 供内部使用之前运行 npm 脚本来复制 dist 文件夹中的 sass 文件(使用 copyfiles).

The only way I found until now is to run an npm script to copy sass files on dist folder (using copyfiles) before package the .tgz for internal use.

这里是我的 package.json:

{
...
     "scripts": {
        "ng": "ng",
        "start": "ng serve",
        "build": "ng build",
        "test": "ng test",
        "lint": "ng lint",
        "e2e": "ng e2e",
        "uiutils_build": "ng build my-library",
        "uiutils_styles": "copyfiles -f projects/my-library/src/scss/*.scss dist/@my-namespace/my-library/scss",
        "uiutils_pack": "cd dist/@my-namespace/my-library && npm pack",
        "uiutils_copy": "copyfiles -f dist/@my-namespace/my-library/*.tgz ../infraestructure.tourbitz.com/packages/@my-namespace/my-library",
        "uiutils_package": "npm run uiutils_build && npm run uiutils_styles && npm run uiutils_pack && npm run uiutils_copy"
      },
...
}

重要的脚本是 uiutils_styles.

the important script is uiutils_styles.

¿如何使用?

在我的样式文件中,我包含了样式:

In my style files, I included the styles:

@import "~@my-namespace/ui-uitils/scss/my_style.scss";

为了注册全局样式,我在 angular.json 文件的项目部分做了:

And for registering global styles I did on the project section of the angular.json file:

{
... 
"architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
"styles": [
              "node_modules/@my-namespace/my-library/scss/my_style.scss",
              "src/styles.scss"
            ],
...
},
...
}

这篇关于如何在 angular 8 库中包含 SASS 样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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