1.0.2 • Published 12 months ago

@icoset/icoset-webpack-plugin v1.0.2

Weekly downloads
44
License
MIT
Repository
-
Last release
12 months ago

Icoset Webpack Plugin

Use Webpack + Icoset to build svg's dynamically into your outputed bundle.

Learn more about icoset: @icoset/icoset

Check out the icoset presets: @icoset/preset-*

What it does

Since Icoset is a build-time tool, we need a way to get all these icons into our app during run-time.

Enter icoset-webpack-plugin - we can now use webpack to initiate Icoset with a custom config, and dynamically inject it into our final bundle.

Install

// yarn
$ yarn add @icoset/icoset @icoset/icoset-webpack-plugin
// npm
$ npm install -s @icoset/icoset @icoset/icoset-webpack-plugin

Use

// webpack.config.js
const IcosetWebpackPlugin = require('@icoset/icoset-webpack-plugin');
const path = require('path');

module.exports = {
  entry: './src/index.js',
  output: {...},
  plugins: [
    new IcosetWebpackPlugin({
      directory: path.resolve(__dirname, 'icons'),
    })
  ],
}

Options

icosetOptions object (Required)

Pass in icoset options here (like directory and icons). Check out the Icoset README to learn more.

entryName string (Optional)

Depending on the webpack configuration, you might have more then one entry file.

This option allows you to target a named entry file for injection:

module.exports = {
  entry: {
    one: './src/one.js',
    two: './src/two.js',
  },
  plugins: [
    new IcosetWebpackPlugin({
      entryName: 'one', // the plugin will inject the icons into this entry file
      icosetOptions: {
        directory: path.resolve(__dirname, 'icons'),
      },
    })
  ],
}

injectionType "onDocumentLoad" | "window" (optional)

Choose how you want your icons added to your app.

  • onDocumentLoad DEFAULT - inject svgs directly into the <body> on document load.
  • window - inject svgs into a window variable for later use (window variable name defaults to window.__icoset).

windowVariableName string (optional)

If injectionType === 'window', you can change that variable name here.

module.exports = {
  plugins: [
    new IcosetWebpackPlugin({
      injectionType: 'window',
      windowVariableName: '__whatever_you_want__',
    })
  ],
}
// output: window.__whatever_you_want__ = "<svg>...</svg>";

Special Thanks

I just want to give a big shout out to our friends behind the webpack-inject-plugin project. This project utilizes that plugin to be able to inject custom code into an entry file.

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

2 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago