Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular 6 whats for style.js in the build

Tags:

sass

angular

Peeping in the html source

of my SPA build with ng 6 using sass

I found these list of files

<script type="text/javascript" src="runtime.js"></script>
<script type="text/javascript" src="polyfills.js"></script>
<script type="text/javascript" src="styles.js"></script>
<script type="text/javascript" src="vendor.js"></script>
<script type="text/javascript" src="main.js"></script>

I'm wondering what's style.js for?

I'm importing bootstrap

in my style.scss like

(I do that because if I put bootstrap in angular.json I can't have my custom theme see variables)

@import "./assets/variables";
@import "~bootstrap/scss/bootstrap";
like image 685
Whisher Avatar asked May 19 '18 15:05

Whisher


People also ask

What is style js in Angular?

The style. js is all your css files that are included in your style array in angular. json file.

How to add styles in@ component in Angular?

There are several ways to add styles to a component: By setting styles or styleUrls metadata. Inline in the template HTML. With CSS imports.

Can we use both CSS and SCSS in Angular?

With the help of Angular CLI, you can install CSS or SCSS on your project and start working on that in a suitable way. If you are working with the CSS or SCSS in your angular project then it is very easy for you as compared to most other frameworks.

What is SCSS file in Angular?

In the Angular CLI, all components are self-contained and so are their Sass files. In order to use a variable from within a component's Sass file, you'll need to import the _variables. scss file. One way to do this is to @import with a relative path from the component.


2 Answers

With the development build global styles are extracted to .js files whereas with the production build they are extracted to .css files. To change this default behavior use --extract-css option or it's alias -ec with the ng build command.

What is the reason for using js to extract css in dev builds?

Every file/module we want to be used in the bundle webpack expects to be a valid JavaScript module. And certainly styles.css is not a valid JavaScript module. So we need something to turn this CSS module into JS module. And this is where loaders come in. Here is what webpack docs say about loaders:

Loaders are transformations that are applied on the source code of a module. They allow you to pre-process files as you import or “load” them… Loaders can transform files from a different language (like TypeScript) to JavaScript, or inline images as data URLs.

More: This is how angular-cli/webpack delivers your CSS styles to the client

like image 103
Vikas Avatar answered Oct 22 '22 21:10

Vikas


The style.js is all your css files that are included in your style array in angular.json file.

like image 1
Nour Avatar answered Oct 22 '22 20:10

Nour