简体   繁体   English

Angular 4 + SASS路径映射

[英]Angular 4 + SASS path mapping

I was wondering if there is anyway to add path mapping for SASS files in Angular 4? 我想知道是否有必要在Angular 4中为SASS文件添加路径映射? What I mean is, lets say I have global scss files stored in src/assets/styles and I would like to access these files in my component scss files which are stored in src/app/component/{component-name}/{component-name}.component.scss. 我的意思是,让我说我有存储在src / assets / styles中的全局scss文件,我想在我的组件scss文件中访问这些文件,这些文件存储在src / app / component / {component-name} / {component -name} .component.scss。 Currently I have to do: 目前,我必须做:

@import "../../../assets/styles/{file-needed}.scss";

When I would like to be able to do something like: 当我希望能够执行以下操作时:

@import "~assets/styles/{file-needed}.scss";

I know the ~ will go to the node_modules dir, that's just an example. 我知道〜将转到node_modules目录,这只是一个示例。 Is there anyway to create a shortcut for these kind of things? 无论如何,有没有为这些事情创建捷径?

Many thanks in advance! 提前谢谢了!

I found the answer. 我找到了答案。 You can add "stylePreprocessorOptions" to the angular-cli.json app object to include any path in your scss compilation. 您可以将“ stylePreprocessorOptions”添加到angular-cli.json应用程序对象,以在您的scss编译中包括任何路径。 Source is here . 来源在这里

update 2019 更新2019

In Angular 6 and newer, in angular.json Angular 6及更高版本中,在angular.json

"projects": {
    "projectName": {
      ...
      "architect": {
        "build": {
          ...
          "options": {
            ...
            "stylePreprocessorOptions": {
              "includePaths": [
                "node_modules",
                "src/app/styles",
                "some/other/path/to/scss"
              ]
            },
            ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM