All Projects → dashed → sizeof-loader

dashed / sizeof-loader

Licence: MIT license
Webpack loader that works like url-loader (or file-loader) but with extracted information such as image dimensions and file-size.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to sizeof-loader

Css Loader
CSS Loader
Stars: ✭ 4,067 (+20235%)
Mutual labels:  loader, webpack-loader
Thread Loader
Runs the following loaders in a worker pool
Stars: ✭ 945 (+4625%)
Mutual labels:  loader, webpack-loader
Inject Loader
💉📦 A Webpack loader for injecting code into modules via their dependencies.
Stars: ✭ 474 (+2270%)
Mutual labels:  loader, webpack-loader
typed-css-modules-loader
💠 Webpack loader for typed-css-modules auto-creation
Stars: ✭ 62 (+210%)
Mutual labels:  loader, webpack-loader
Style Loader
Style Loader
Stars: ✭ 1,572 (+7760%)
Mutual labels:  loader, webpack-loader
Markdown Loader
markdown loader for webpack
Stars: ✭ 335 (+1575%)
Mutual labels:  loader, webpack-loader
Stylefmt Loader
Webpack-loader. Fixes stylelint issues automatically while bundling with Webpack.
Stars: ✭ 24 (+20%)
Mutual labels:  loader, webpack-loader
angular-translate-loader
"angular-translate" loader for webpack
Stars: ✭ 15 (-25%)
Mutual labels:  loader, webpack-loader
Sass Vars Loader
Use Sass variables defined in Webpack config or in external Javascript or JSON files
Stars: ✭ 112 (+460%)
Mutual labels:  loader, webpack-loader
Vue Svg Inline Loader
Webpack loader used for inline replacement of SVG images with actual content of SVG files in Vue projects.
Stars: ✭ 105 (+425%)
Mutual labels:  loader, webpack-loader
nunjucks-loader
Webpack loader for Nunjucks templates
Stars: ✭ 20 (+0%)
Mutual labels:  loader, webpack-loader
Rust Native Wasm Loader
Stars: ✭ 156 (+680%)
Mutual labels:  loader, webpack-loader
webpack-modernizr-loader
Get your modernizr build bundled with webpack, use modernizr with webpack easily
Stars: ✭ 35 (+75%)
Mutual labels:  loader, webpack-loader
Sass Loader
Compiles Sass to CSS
Stars: ✭ 3,718 (+18490%)
Mutual labels:  loader, webpack-loader
markup-inline-loader
a webpack loader to embed svg/MathML to html
Stars: ✭ 24 (+20%)
Mutual labels:  loader, webpack-loader
Wasm Loader
✨ WASM webpack loader
Stars: ✭ 604 (+2920%)
Mutual labels:  loader, webpack-loader
jsx-compress-loader
⚛️JSX optimisation loader to reduce size of React application
Stars: ✭ 40 (+100%)
Mutual labels:  loader, webpack-loader
image-minimizer-webpack-plugin
Webpack loader and plugin to compress images using imagemin
Stars: ✭ 180 (+800%)
Mutual labels:  loader, webpack-loader
Svgr
Transform SVGs into React components 🦁
Stars: ✭ 8,263 (+41215%)
Mutual labels:  loader, webpack-loader
Vue Pretty Logger
The console is more cool to use, easier to debug, and more fun log output. Enjoy the vue-pretty-logger in the vue project.
Stars: ✭ 150 (+650%)
Mutual labels:  loader, webpack-loader

sizeof-loader Build Status npm version

Webpack loader that works like url-loader (or file-loader) but with extracted information such as image dimensions and file-size.

Install

yarn add --dev sizeof-loader
# or
npm install --save-dev sizeof-loader

Usage

// webpack.confg.js

// ...

module.exports = {
    module: {
        rules: [
            {
                test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
                use: [
                    {
                        loader: "sizeof-loader",

                        options: {
                            // default is false
                            useFileLoader: false,

                            // any options will be passed to file-loader or url-loader
                            limit: 10000,
                            name: "static/media/[name].[hash:8].[ext]"
                        }
                    }
                ]
            }
        ]

        // ...
    }

    // ...
};
// path/to/amazing/app/src/components/logo.js

import logo_img from "images/logo.png";

// logo_img is:
{

    // Output emitted from either:
    // - https://github.com/webpack-contrib/file-loader
    // - https://github.com/webpack-contrib/url-loader
    src: 'path/to/logo.png',

    // Output emitted by: https://github.com/image-size/image-size
    width: 400,
    height: 200,
    bytes: 12345,
    type: 'png',

    // useful for console.log
    toString: function() { /* ... */ }
}

Options (webpack)

By default, useFileLoader is false.

If useFileLoader is false, then url-loader is wrapped. Any given options will be passed onto this loader.

However, if you pass useFileLoader: true, then file-loader will be used, and any given options will be passed onto that loader.

Supported file-types

image-size is used internally.

See: https://github.com/image-size/image-size#supported-formats

Use case

// project_root/src/components/logo.js

import styled from "styled-components";

import logo_img from "images/logos/homepage.png";
import { bg_image } from "styles/mixins";

const Logo = styled.div`
    display: inline-block;

    ${bg_image(logo_img, /* resolution */ 2)};
`;

export default Logo;
// project_root/src/styles/mixins.js

import { css } from "styled-components";

export const bg_image = (resolved_image, resolution) => {
    const width = `${resolved_image.width / resolution}px`;
    const height = `${resolved_image.height / resolution}px`;

    return css`

        background-image: url('${resolved_image.src}');
        background-repeat: no-repeat;
        background-position: center;
        background-size: ${width} ${height};

        height: ${height};
        width: ${width};

    `;
};

Credits

Code is based on: https://github.com/boopathi/image-size-loader but wraps url-loader and file-loader.

Development

Chores

  • Lint: yarn run lint
  • Prettier: yarn run pretty
  • Test: yarn run test
  • Pre-publish: yarn run prepublish
  • Build: yarn run build

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].