Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.scss files not processed from index.html #1787

Closed
PiusNyakoojo opened this issue Aug 21, 2016 · 12 comments
Closed

.scss files not processed from index.html #1787

PiusNyakoojo opened this issue Aug 21, 2016 · 12 comments

Comments

@PiusNyakoojo
Copy link
Contributor

PiusNyakoojo commented Aug 21, 2016

Bug Report

.scss files aren't processed to css when included via link tag in index.html

(this would be useful for global styles: e.g. styling the body as this doesn't seem to work in the default app.component.css)

Expected Behavior

.scss files are processed to css if they are included via a link tag in the index.html file.

Actual Behavior

.scss files aren't processed in index.html

Reproduction

  • Create a new project

ng new project-name --prefix pn

  • Add .scss support

ng set defaults.styleExt scss

  • Add link to index.html
<head>
<!-- other things -->

<!-- This could work if webpack were configured to check if theme.css exists; if not, then check for theme.scss and process that -->
<link rel="stylesheet" type="text/css" href="theme.css">


<!-- This doesn't work either.
<link rel="stylesheet" type="text/css" href="theme.scss">
-->
</head>
  • Create theme.scss
@import './variables'

body {
background-color: $bg-color;
}
  • Create variables.scss

$bg-color: red;

  • Serve

ng serve

Version details:

OS: Windows 10
node: 6.3.1
angular-cli@1.0.0-beta.11-webpack.2

@cport1
Copy link

cport1 commented Aug 21, 2016

can you copy and paste your component code?

@deebloo
Copy link
Contributor

deebloo commented Aug 21, 2016

@PiusNyakoojo sass will not compile your styles when including them that way. you can only link stylesheets that way if they are static assets. In the current master of the cli you can point to a main stylesheet which can be sass.

@deebloo
Copy link
Contributor

deebloo commented Aug 21, 2016

if you have a global static stylesheet you want to include you can put it in the public folder. Or if using master in src/assets

@keithmichelson
Copy link

keithmichelson commented Aug 22, 2016

I've tried to put a .scss file in the public folder, but on build it doesn't process it into a css file.

@sirajc
Copy link

sirajc commented Aug 22, 2016

see #1459

@PiusNyakoojo
Copy link
Contributor Author

@sirajc Thanks.

This PR addresses my concern: #1633

In short:

When this request is merged to the main branch (when the angular-cli team releases the next version of the cli), we can add "styles": "our.style.scss" to angular-cli.json as part of the apps[0] metadata.

Concretely:

"apps": [
    {
      "main": "src/main.ts",
      "tsconfig": "src/tsconfig.json",
      "mobile": false,
      "styles": "src/our.style.scss" // Available in next version of angular-cli
    }
  ],

@kennyrulez
Copy link

Hello,
sorry to comment an already closed issue, but I need to clarify myself with.
My config OS: Windows 10 node: 6.3.1 angular-cli@1.0.0-beta.11-webpack.2

If i create in [myproject]/src/app/style.scss this file is ignored by angular-cli and it's not compiled and published alongside the other files?
Just scss in components are parsed when calling ng serve (or ng build)?

Thanks for any clarifications!

@PiusNyakoojo
Copy link
Contributor Author

PiusNyakoojo commented Aug 24, 2016

@kennyrulez here are a few things you could check

1. Did you create this project with

ng project-name --style=sass

No? Then did you add sass support with

ng set defaults.styleExt scss

2. Is style.scss referenced in one of your components?

// for example

@Component({
  templateUrl: './app.component.html',
  stylesUrl: ['./style.scss']
})

3. Are you trying to style the body tag? For this, you may want to make the stylesheet global

// reference your styles in angular-cli.json

"apps": [
   {
       // ... other stuff
      "styles": [
         "./src/style.scss" // reference your style sheet here
      ]
   }
]

Note: ng serve is just ng build + watching your files for changes then rebuilding and reloading page

@kennyrulez
Copy link

@PiusNyakoojo thanks for your response. Number 3 is exactly what i want to achieve.
I modified angular-cli.json as you suggest

"apps": [
    {
      "main": "src/main.ts",
      "tsconfig": "src/tsconfig.json",
      "mobile": false,
       "styles": [
         "./src/app/app.scss"
      ]
    }

and referenced in index.html as
<link rel="stylesheet" type="text/css" href="app/app.css">

No way of getting it working. It seems is not compiling it nor bundling it.

Thanks for your help!

@Kosmonaft
Copy link

I hope you don't have mind to join to your conversation.
Currently Im struggling with global_variables.scss` file.

My project is using sass and I want to create one scss file with all variable of my project (something like an global scss). When I am including this _variables.scss file into my app.component.ts or importing into app.component.scss only the stylesheets for app.component are seeing this variables..
When I`m trying to use some variable in another scss I am receiving an error:

Module build failed: xxx xxx Undefined variable: "xxx".

Is it possible to have a _variable.scss and use it variables without including it in every single component?

@martoncsikos
Copy link

See response by filipesilva in #1780.
Apparently the global styles configuration is the way to go, but it made it into the documentation before the actual release, so you have to wait for the next webpack release for it to actually work.

"apps": [
   {
       // ... other stuff
      "styles": [
         "./src/style.scss" // reference your style sheet here
      ]
   }
]

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants