Giter Club home page Giter Club logo

hoc-loader's Introduction

hoc-loader

โš ๏ธ Warning: This loader is tested only with a single loader (desvg-loader) and a simple use case in mind.

hoc-loader is a webpack loader that allows to wrap the result of the previous loader in the chain into a high-order component.

Installation

npm i hoc-loader --save-dev
# or
yarn add --dev hoc-loader

Configuration

// ...
{
  test: /\.svg$/,
  use: [
    {
      loader: 'hoc', // ๐Ÿ‘ˆ Add loader
      options: {
        // ๐Ÿ‘‡ The path to the HoC file. It must be absolute to the FS root
        // or relative to the instrumented file.
        path: '/path/to/Icon/index.jsx',

        // ๐Ÿ‘‡ Depending on how HoC file is built, (e.g. if you use Babel
        // along with ES Modules) you may need to enable this option,
        // so the HoC file will be required as `require('path/to/hoc').default`.
        //
        // `false` by default
        useDefault: true,

        // ๐Ÿ‘‡ The name of the export var used by the previous loader.
        // It depends on the loader, e.g. css-loader exports CSS Modules
        // into `exports.locals`, while svg-loader uses `module.exports`.
        //
        // `module.exports` by default
        exportVar: 'exports.locals'
      }
    },
    'desvg/react',
    'svg'
  ],

  // or if you prefer classic:

  loader: `hoc?useDefault&path=/path/to/Icon/index.jsx!desvg/react&exportVar!svg`
},
// ...

Example

See a HoC example (in combination with desvg):

import React from 'react'
import { Wrapper } from './style.css'

export default function (Svg) {
  return function Icon ({ width = '2rem' }) {
    return (
      <div style={{ width }}>
        <Svg fill='currentColor' />
      </div>
    )
  }
}

License

MIT ยฉ Sasha Koss

hoc-loader's People

Contributors

kossnocorp avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.