2

In an older, complex code base that uses Angular 4 with a custom Webpack, there were some components that imported a css file, in the same way that you would import a module for a side effect. An example (this is the complete file, with different variable names):

import { Component, OnInit } from '@angular/core';
import '../../assets/css/styles.css';

@Component({
    selector: 'sidebar-app',
    templateUrl: './sidebar.component.html',
    styleUrls: ['./sidebar.component.css']
})
export class SidebarComponent implements OnInit {

    ngOnInit() {
    }
}

styles.css

.content_body {
    padding: 0;
}

.basic_page_wrapper {
    padding: 0;
}

I have never seen css being imported in typescript, and all other examples I've found use the styles in some way, for example

import * as s from './Button.css';

Why would a css file be imported like import '../../assets/css/styles.css'; inside an angular component?

1 Answer 1

3

When using bundlers such as webpack or browserify, one might import a CSS file in order to process it and pack it into the same bundle as the JavaScript module that imports it.

In webpack, this is done using the style-loader. Read more in this medium post!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.