Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
stylus-loader
Advanced tools
The stylus-loader npm package is a utility that allows you to load and compile Stylus files directly in Webpack. This integration facilitates the use of Stylus, a pre-processor for CSS, enabling developers to write cleaner and more efficient style sheets by utilizing variables, functions, and mixins.
Loading and Compiling Stylus Files
This feature allows developers to integrate Stylus files into their Webpack build process. The provided code configures Webpack to use stylus-loader along with css-loader and style-loader to process files ending in .styl, compile them into CSS, and inject them into the DOM.
module.exports = {
module: {
rules: [
{
test: /\.styl$/,
use: [
'style-loader',
'css-loader',
'stylus-loader'
]
}
]
}
};
Custom Import Paths
This feature allows the specification of custom paths where Stylus files are located, making it easier to organize and maintain stylesheets. The code sample demonstrates how to add custom paths to the stylus-loader configuration in Webpack.
module.exports = {
module: {
rules: [
{
test: /\.styl$/,
use: [
'style-loader',
'css-loader',
{
loader: 'stylus-loader',
options: {
paths: ['node_modules', 'path/to/import/dir']
}
}
]
}
]
}
};
Similar to stylus-loader, sass-loader is used to compile Sass files into CSS within the Webpack build process. While both loaders serve a similar purpose for different CSS pre-processors (Stylus for stylus-loader and Sass/SCSS for sass-loader), the choice between them typically depends on the specific syntax and features preferred by the developer.
less-loader functions similarly to stylus-loader but for Less files. It integrates with Webpack to compile Less into CSS. Like stylus-loader, it supports customizations such as modifying variable values and managing import paths. The main difference lies in the syntax and capabilities of Less compared to Stylus.
var css = require('!raw!stylus!./file.styl'); // Just the CSS
var css = require('!css!stylus!./file.styl'); // CSS with processed url(...)s
See css-loader to see the effect of processed url(...)
s.
Or within the webpack config:
module: {
loaders: [{
test: /\.styl$/,
loader: 'css-loader!stylus-loader?paths=node_modules/bootstrap-stylus/stylus/'
}]
}
Then you can: var css = require('./file.styl');
.
Use in tandem with the style-loader to add the css rules to your document
:
module: {
loaders: [
{ test: /\.styl$/, loader: 'style-loader!css-loader!stylus-loader' }
]
}
and then require('./file.styl');
will compile and add the CSS to your page.
stylus-loader
can also take advantage of webpack's resolve options. With the default options it'll find files in web_modules
as well as node_modules
, make sure to prefix any lookup in node_modules with ~
. For example if you have a styles package lookup files in it like @import '~styles/my-styles
. It can also find stylus files without having the extension specified in the @import
and index files in folders if webpack is configured for stylus's file extension.
module: {
resolve: {
extensions: ['', '.js', '.styl']
}
}
will let you have an index.styl
file in your styles package and require('styles')
or @import '~styles'
it. It also lets you load a stylus file from a package installed in node_modules or if you add a modulesDirectories, like modulesDirectories: ['node_modules', 'web_modules', 'bower_components']
option you could load from a folder like bower_components. To load files from a relative path leave off the ~
and @import 'relative-styles/my-styles';
it.
Be careful though not to use the extensions configuration for two types of in one folder. If a folder has a index.js
and a index.styl
and you @import './that-folder'
, it'll end up importing a javascript file into your stylus.
You can also use stylus plugins by adding an extra stylus
section to your webpack.config.js
.
var stylus_plugin = require('stylus_plugin');
module: {
loaders: [
{ test: /\.styl$/, loader: 'style-loader!css-loader!stylus-loader' }
]
},
stylus: {
use: [stylus_plugin()]
}
npm install stylus-loader --save-dev
npm test
open http://localhost:8080/test/
In lieu of a formal styleguide, take care to maintain the existing coding style.
Copyright (c) 2014 Kyle Robinson Young
Licensed under the MIT license.
FAQs
Stylus loader for webpack
The npm package stylus-loader receives a total of 802,575 weekly downloads. As such, stylus-loader popularity was classified as popular.
We found that stylus-loader demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers 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
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.