
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
styles-loader
Advanced tools
This is a webpack boilerplate that covers all plugins and loaders that are necessary to load .css, .less and | or .sass files into your project. Use npm install styles-loader rather than installing all css, sass and less loaders and plugins separately.
npm install styles-loader --save-dev
webpack.config.js webpack-merge module to combine plenty webpack configs into one [read more]styles-loader, create the new instance of it and inject it with merge moduleconst { merge } = require('webpack-merge');
const StylesLoader = require('styles-loader'); //this is a [Function] constructor
const stylesLoader = new StylesLoader(); //create new instace with all ready-to-use webpack rules, plugins, etc.
module.exports = merge(stylesLoader, {
//your webpack settings here
entry:'./index.js',
output:{
path: path.join(__dirname, 'dist'),
publicPath: 'dist/'
}
});
index.js file import './css/styles.css';
import './scss/bootstrap.scss';
import './less/grid.less';
.css, .sass and .less files with url() and @import keywords will be stored in the ./dist/assets/images and ./dist/assets/misc directories..css, .sass and .less files will be parsed to css and added to the DOM by injecting a <style> tagThe new StylesLoader([object]) takes the (optional) [Object] config object, that lets to customize how the webpack loaders behave under the hood.
const StylesLoader = require('styles-loader');
const stylesLoader = new StylesLoader({ //[Object] argument
extract: 'styles.css', //it creates the bundled styles.css file rather than add <style> tags in the html file
url:{/* the url-loader and file-loader options here for .woff, .ttf, .eot, .svg files */},
file:{/* the file-loader options here for .jpg, .png, .gif files */},
css:{/* the css-loader options here */},
styles:{/*the style-loader options here */}
sass:{/* the sass-loader options here */},
less:{/*the less-loader options here */}
});
<style> or <link> in your html file.css, .sass and .less files will be parsed to .css and added to the DOM by injecting a <style> tag automatically.css file from all imported .css, .sass and .less files, add extract property to the [Object] config. It should indicate the [String] path to the new bundled css file, eg: "dist/styles.css"<link rel="stylesheet" href="dist/styles.css"/> into your .html fileconst { merge } = require('webpack-merge');
const StylesLoader = require('styles-loader');
const stylesLoader = new StylesLoader({
extract: 'styles.css'
});
module.exports = merge(stylesLoader, {
//your webpack settings here
entry:'./index.js',
output:{
path: path.join(__dirname, 'dist')
}
});
config.cssDefault: {}
css-loader optionscss-loader is used to resolve all @imports and url()sconst stylesLoader = new StylesLoader({
css: {
url: false
}
});
config.styleDefault: {}
style-loader optionsstyle-loader is used to add the <style> tags into the html file with all stylesheets'extract' config property is not defined (because then the bundled .css file is created)const stylesLoader = new StylesLoader({
style: {
insert: 'head'
}
});
config.sassDefault: {}
sass-loader optionssass-loader is used to compile the scss into cssconst stylesLoader = new StylesLoader({
sass: {
outputStyle: 'compressed'
}
});
config.lessDefault: {}
less-loader optionsless-loader is used to compile the less into cssconst stylesLoader = new StylesLoader({
less: {
math:'[parens-division]'
}
});
config.urlDefault: { limit: 8192, name: '[name].[ext]', outputPath: './assets/misc' }
url-loader optionsurl-loader is used to transform small files (woff, ttf, eot, svg) into base64 URIsconst stylesLoader = new StylesLoader({
url: {
limit: 20000 //only the files bigger than 20000 bytes will be stored in assets folder
}
});
config.fileDefault: { name: '[name].[ext]', outputPath: './assets/images' }
file-loader optionsfile-loader is used to emit all url() and @import required jpg, png, gif files into the output directoryconst stylesLoader = new StylesLoader({
file: {
name: '[hash].[ext]',
outputPath:'assets/'
}
});
config.imageDefault: {}
image-webpack-loader optionsimage-webpack-loader is used to optimize jpg, png, gif filesconst stylesLoader = new StylesLoader({
image: {
mozjpeg: {
progressive: true,
quality: 65
}
}
});
git clone https://github.com/devrafalko/styles-loader.git
cd styles-loader/sample
npm install
npm start or npm run build
Check out how the webpack config files look like and how all assets files are handled.
FAQs
Install all necessary webpack css, sass and less loaders at once
The npm package styles-loader receives a total of 1,212 weekly downloads. As such, styles-loader popularity was classified as popular.
We found that styles-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.