Skip to content

MichaelCurrin/css-loader-quickstart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CSS Loader Quickstart

Starter template for using CSS Loader and Webpack

GitHub tag License

Made with Node.js

Package - webpack Package - css-loader Package - style-loader

Use this project

Use this template

Installation

Install Node.js.

Clone the repo.

Install project packages with:

$ npm install

Usage

Watch

Bundle the JS and CSS with webpack. This will watch continuously.

$ npm start

Then open a dev server in the dist directory and open localhost in your browser.

Build

Do a build and then stop.

$ npm run build

You might want to switch to using production settings in the Webpack config.

About

How it works

When running Webpack the JS file index.js and styling imports gt bundled as a single JS file. In particular, there is a local CSS file (styles.css) and an installed CSS dependency (sanitize.css).

The CSS gets added to the JS because of two CSS loading dependencies that are installed and also because Webpack is configured to use those dependencies for CSS files. See webpack.config.js.

When the bundled JS file (bundle.js) gets loaded on the frontend, the JS will inserted the CSS into the DOM for you. So you don't need to add a style or link tag yourself.

Dependencies

Set up

Set the dependencies up in a fresh project with:

$ npm i -D webpack webpack-cli css-loader style-loader $ npm i sanitize.css

License

Released under MIT by @MichaelCurrin.

About

Starter template for using CSS Loader and Webpack

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published