如何在Angular中缩短文件路径? [英] How to short path to file in Angular?

查看:29
本文介绍了如何在Angular中缩短文件路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我导入的一些 CSS 文件中:

In some CSS files I have import:

@import "../../../theme.scss"
@import "../../theme.scss"
@import "../../../../../../theme.scss"
@import "../theme.scss"

如何在所有情况下都使用相对路径作为绝对路径:

How to use relative path as absolute path everywhere for all cases:

@import "theme.scss"

我完整的 angulr.json 代码是:

My full angulr.json code is:

"reon-core": {
      "projectType": "library",
      "root": "projects/reon-core",
      "sourceRoot": "projects/reon-core/src",
      "prefix": "lib",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-ng-packagr:build",
          "options": {
            "stylePreprocessorOptions": {
              "includePaths": ["./projects/reon-core/src/lib/tssource/"]
            },
            "tsConfig": "projects/reon-core/tsconfig.lib.json",
            "project": "projects/reon-core/ng-package.json"
          }
        }

....它返回数据路径"不应该有额外的属性(stylePreprocessorOptions).;

推荐答案

只需在angular.json文件中添加stylePreprocessorOptions的路径即可:

Just add the path to the stylePreprocessorOptions in the angular.json file:

"architect": {
        "build": {
          ...
          "options": {
            ...
            "stylePreprocessorOptions": {
              "includePaths": [
                "./src/assets/style/theme"
              ]
            },
         },
         "test": {
           ...
           "options": {
             ...
             "stylePreprocessorOptions": {
               "includePaths": [
                 "./src/assets/style/theme"
               ]
             }
           }
         }
}

然后你应该能够像 @import 'app-theme.scss';

我想你设置了错误的相对路径.您的根文件夹应该是 reon-core.因此,您需要像这样设置 stylePreprocessorOptions:

I suppose you set the wrong relative path. Your root folder should be reon-core. Therefore you need to set the stylePreprocessorOptions like that:

"includePaths": ["./src/lib/tssource/"]

buildtest

设置后,您可以在那里放入任何主题文件,例如:

After you set this, you can put in any theme file there and like:

./src/lib/tssource/theme.scss 并像 @import 'theme.scss';

这篇关于如何在Angular中缩短文件路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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