Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

185
Visualizações
Angular Dynamic styleUrls with environment variable are not loaded by StorybookJS

Currently I'm working on a project where we are building our application in multiple styles. Our components have one base component.scss file and multiple stylesheets for the project-specific styling. With an environment variable we let angular know which stylesheets to compile. So for every component the following stylesheets exist: button.component.scss, button.component.stylea.scss and button.component.styleb.scss. In the component itself, we use the environment variable to declare the specific file to use:

@Component({
  selector: 'button[app-button]',
  templateUrl: 'button.component.html',
  // Below should become button.component.stylea.scss
  styleUrls: ['button.component' + environment.componentScssExtension] 
})

In our environment file, we have:

componentScssExtension: '.stylea.scss',

For Angular to build the project, this works fine. We have two npm commands to choose which build config te use (either stylea or styleb). However, when running StorybookJS, it seems the environment variable is not being used and we get an unstyled button component, even though we do set the angular config to let storybook know which environment files to use:

"storybook": {
  "builder": "@storybook/angular:start-storybook",
  "options": {
    "browserTarget": "APP:build",
    "styles": [
      "src/styles.scss"
    ]
  },
  "configurations": {
    "stylea": {
      "browserTarget": "APP:build:dev-stylea"
    },
    "styleb": {
      "browserTarget": "APP:build:dev-styleb"
    }
  }
}

In dev-stylea and dev-styleb, we tell which environment to use.

"dev-stylea": {
  "assets": [
    "src/assets",
    "src/assets/images/favicon.ico"
  ],
  "fileReplacements": [
    {
      "replace": "src/environments/environment.ts",
      "with": "src/environments/environment.stylea.ts"
    }
  ],
  "styles": [
    "src/styles.scss",
    "src/styles/stylea/stylea.scss"
  ]
},

StorybookJS gives no errors when compiling and we do see the button, but dynamically setting the styleUrls in our component like this (styleUrls: ['button.component' + environment.componentScssExtension]) doesn't seem to work for StorybookJS. Does anyone have a solution?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda