Reputation: 10035
Am I correct in understanding that Webpack transforms everything you have into JS code only? So that even if you have CSS, it will be turn into JS (in a bundle) as long as you have the correct loader?
Loaders can transform files from a different language like CoffeeScript to JavaScript, or inline images as data URLs. Loaders even allow you to do things like require() css files right in your JavaScript!”
Upvotes: 0
Views: 117
Reputation: 5752
Loaders won't convert CSS
into JavaScript
but it will allow you to import CSS
files right from your JavaScript
file. For e.g. you have components based application architecture and each component has it's own CSS, you can load css right from component's JS file.
import styles from './app.css';
import './app.css';
Loaders can transform files from a different language (like TypeScript) to JavaScript, or inline images as data URLs. Loaders even allow you to do things like import CSS files directly from your JavaScript modules!
For example, you can use loaders to tell webpack to load a CSS file or to convert TypeScript to JavaScript. To do this, you would start by installing the loaders you need:
npm install --save-dev css-loader
npm install --save-dev ts-loader
And then instruct webpack to use the css-loader for every .css file and the ts-loader for all .ts files:
Upvotes: 1