All Projects → yenshih → Style Resources Loader

yenshih / Style Resources Loader

Licence: mit
CSS processor resources loader for webpack

Programming Languages

typescript
32286 projects
stylus
462 projects

Projects that are alternatives of or similar to Style Resources Loader

Sass Loader
Compiles Sass to CSS
Stars: ✭ 3,718 (+1637.38%)
Mutual labels:  webpack, loader, scss, sass
Sass Vars Loader
Use Sass variables defined in Webpack config or in external Javascript or JSON files
Stars: ✭ 112 (-47.66%)
Mutual labels:  webpack, loader, scss, sass
Bootstrap 4 Utilities
Bootstrap 4 utility classes in LESS CSS for Bootstrap 3 or any other projects.
Stars: ✭ 105 (-50.93%)
Mutual labels:  scss, sass, less
Rollup Plugin Styles
🎨 Universal Rollup plugin for styles: PostCSS, Sass, Less, Stylus and more.
Stars: ✭ 116 (-45.79%)
Mutual labels:  scss, sass, less
Gulp Starter Kit
A simple Gulp 4 Starter Kit for modern web development.
Stars: ✭ 134 (-37.38%)
Mutual labels:  scss, sass, less
Vertical Rhythm
Put some typographical vertical rhythm in your CSS. LESS, Stylus and SCSS/SASS versions included.
Stars: ✭ 83 (-61.21%)
Mutual labels:  scss, sass, less
Wordless
All the power of Pug, Sass, Coffeescript and WebPack in your WordPress theme. Stop writing themes like it's 1998.
Stars: ✭ 1,374 (+542.06%)
Mutual labels:  webpack, scss, sass
Frasco
Quick starter for Jekyll including full setup for Sass, PostCSS, Autoprefixer, stylelint, Webpack, ESLint, imagemin, Browsersync, etc.
Stars: ✭ 123 (-42.52%)
Mutual labels:  webpack, scss, sass
React Redux Antdesign Webpack Starter
react + redux + ant design + react-router 4 + webpack 4 starter
Stars: ✭ 44 (-79.44%)
Mutual labels:  webpack, sass, less
Reactql
Universal React+GraphQL starter kit: React 16, Apollo 2, MobX, Emotion, Webpack 4, GraphQL Code Generator, React Router 4, PostCSS, SSR
Stars: ✭ 1,833 (+756.54%)
Mutual labels:  webpack, sass, less
Kirby Webpack
💪 A Kirby CMS starter-kit with modern frontend tools
Stars: ✭ 150 (-29.91%)
Mutual labels:  webpack, sass, less
React Native Sass Transformer
Use Sass to style your React Native apps.
Stars: ✭ 151 (-29.44%)
Mutual labels:  loader, scss, sass
Cessie
Transpile your CSS bundle to support CSS variables, calc, and future CSS for legacy browsers.
Stars: ✭ 81 (-62.15%)
Mutual labels:  scss, sass, less
Stylelint
A mighty, modern linter that helps you avoid errors and enforce conventions in your styles.
Stars: ✭ 9,350 (+4269.16%)
Mutual labels:  scss, sass, less
Vue Spa
vue-spa : vue + vue-router + axios + vuex + vux 快速成型移动端项目,直接使用。欢迎star
Stars: ✭ 46 (-78.5%)
Mutual labels:  webpack, sass, less
Static Site Boilerplate
A better workflow for building modern static websites.
Stars: ✭ 1,633 (+663.08%)
Mutual labels:  webpack, sass, less
Compile Hero
🔰Visual Studio Code Extension For Compiling Language
Stars: ✭ 169 (-21.03%)
Mutual labels:  scss, sass, less
Cusca
A ghost theme
Stars: ✭ 42 (-80.37%)
Mutual labels:  webpack, scss, sass
Tris Webpack Boilerplate
A Webpack boilerplate for static websites that has all the necessary modern tools and optimizations built-in. Score a perfect 10/10 on performance.
Stars: ✭ 1,016 (+374.77%)
Mutual labels:  webpack, scss, sass
Glup
Some of the gulp tutorial -《gulp笔记》
Stars: ✭ 136 (-36.45%)
Mutual labels:  scss, sass, less

npm node downloads build coverage 996.icu

Style Resources Loader

CSS processor resources loader for webpack.

Install

npm i style-resources-loader -D

Usage

This loader is a CSS processor resources loader for webpack, which injects your style resources (e.g. variables, mixins) into multiple imported css, sass, scss, less, stylus modules.

It's mainly used to

  • share your variables, mixins, functions across all style files, so you don't need to @import them manually.
  • override variables in style files provided by other libraries (e.g. ant-design) and customize your own theme.

Usage with Vue CLI

See automatic imports for more details.

Examples

Prepends variables and mixins to all scss files with default resources injector.

webpack.config.js

module.exports = {
    // ...
    module: {
        rules: [{
            test: /\.scss$/,
            use: ['style-loader', 'css-loader', 'sass-loader', {
                loader: 'style-resources-loader',
                options: {
                    patterns: [
                        './path/from/context/to/scss/variables/*.scss',
                        './path/from/context/to/scss/mixins/*.scss',
                    ]
                }
            }]
        }]
    },
    // ...
}

Appends variables to all less files and overrides original less variables.

webpack.config.js

module.exports = {
    // ...
    module: {
        rules: [{
            test: /\.less$/,
            use: ['style-loader', 'css-loader', 'less-loader', {
                loader: 'style-resources-loader',
                options: {
                    patterns: path.resolve(__dirname, 'path/to/less/variables/*.less'),
                    injector: 'append'
                }
            }]
        }]
    },
    // ...
}

Prepends variables and mixins to all stylus files with customized resources injector.

webpack.config.js

module.exports = {
    // ...
    module: {
        rules: [{
            test: /\.styl$/,
            use: ['style-loader', 'css-loader', 'stylus-loader', {
                loader: 'style-resources-loader',
                options: {
                    patterns: [
                        path.resolve(__dirname, 'path/to/stylus/variables/*.styl'),
                        path.resolve(__dirname, 'path/to/stylus/mixins/*.styl')
                    ],
                    injector: (source, resources) => {
                        const combineAll = type => resources
                            .filter(({ file }) => file.includes(type))
                            .map(({ content }) => content)
                            .join('');

                        return combineAll('variables') + combineAll('mixins') + source;
                    }
                }
            }]
        }]
    },
    // ...
}

Options

Name Type Default Description
patterns {string | string[]} / Path to the resources you would like to inject
injector {Function | 'prepend' | 'append'} 'prepend' Controls the resources injection precisely
globOptions {Object} {} An options that can be passed to glob(...)
resolveUrl {boolean} true Enable/Disable @import url to be resolved

See the type definition file for more details.

patterns

A string or an array of string, which represents the path to the resources you would like to inject. If the path is relative, it would relative to webpack context.

It supports globbing. You could include many files using a file mask.

For example, './styles/*/*.less' would include all less files from variables and mixins directories and ignore reset.less in such following structure.

./src  <-- webpack context
  /styles
    /variables
      |-- fonts.less
      |-- colors.less
    /mixins
      |-- size.less
    |-- reset.less

Only supports .css .sass .scss .less .styl as resources file extensions.

injector

An optional function which controls the resources injection precisely. It also supports 'prepend' and 'append' for convenience, which means the loader will prepend or append all resources to source files, respectively.

It defaults to 'prepend', which implements as an injector function internally.

Furthermore, an injector function should match the following type signature:

(source: string, resources: StyleResource[]) => string | Promise<string>

It receives two parameters:

Name Type Default Description
source {string} / Content of the source file
resources {StyleResource[]} / Resource descriptors

resources

An array of resource descriptor, each contains file and content properties:

Name Type Default Description
file {string} / Absolute path to the resource
content {string} / Content of the resource file

It can be asynchronous. You could use async / await syntax in your own injector function or just return a promise.

globOptions

Options that can be passed to glob(...). See node-glob options for more details.

resolveUrl

A boolean which defaults to true. It represents whether the relative path in @import or @require statements should be resolved.

If you were to use @import or @require statements in style resource files, you should make sure that the URL is relative to that resource file, rather than the source file.

You could disable this feature by setting resolveUrl to false.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].