Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
165
rated 0 times [  172] [ 7]  / answers: 1 / hits: 50342  / 8 Years ago, fri, january 13, 2017, 12:00:00

How do i include css file in tsx and how to use it?
i.e how do i render static files?



import * as React from react;
import { Header } from ./header;

//import ./home.css;


export class Home extends React.Component<{}, {}> {
render() {
return (
<div id=page-top className=landing-page>
<Header />
</div>
);
}
}

More From » css

 Answers
20

You cannot directly import CSS or any other static files into typescript using only the typescript compiler, but you can with the help of some build tools...



For example using webpack, you can set up the css-loader and style-loader to search your source code for require('./whatever.css') and add it to the build before safely compiling your typescript. If you also have webpack generate your HTML then your CSS will be automatically injected as a stylesheet.


[#59366] Wednesday, January 11, 2017, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
luna

Total Points: 698
Total Questions: 114
Total Answers: 93

Location: Israel
Member since Wed, Apr 14, 2021
3 Years ago
luna questions
;