npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

parcel-transformer-elm-svg-modules

v1.0.6

Published

Elm and SVGs are both awesome. Luckily parcel can help us turn SVG straight into an Elm module.

Downloads

2,730

Readme

Have parcel turn svg into elm modules for you

Elm and SVGs are both awesome. Luckily parcel can help us turn SVG straight into an Elm module.

This plugin is for ParcelJS 📦 version 2

Installing and Setup

npm i -D parcel-transformer-elm-svg-modules

Then in your .parcelrc add the transformer BEFORE the regular Elm transform (the svg modules need to be generated before Elm is compiled)

{
  "extends": "@parcel/config-default",
  "transformers": {
    "*.elm": ["parcel-transformer-elm-svg-modules", "..."] // <-- add the new transform here, the "..." is important to keep the other defaults
  }
}

Configuration

To configure, add this to your package.json. The following entry would load SVGs from src/assets/images/ and combine them into an Elm Module named Icons located at src/Icons.elm. You can add more entries to the array to generate multiple modules. Here's an example:

  "elmSvgModules": [
    {
      "inputSvgs": "src/assets/images/svg/*.svg", // a glob pattern to place where your SVGs are
      "outputModuleName": "Icons", // the module name of the Elm module that will be generated
      "outputModuleDir": "src" // the location where Elm module will be generated
    }
  ],

| Option | Required | Default | | ------ | ------- | ------- | | inputSvgs | Yes | - | | outputModuleName | No | Icons | | outputModuleDir | no | src |

outputModuleName can also be something like Acme.Icons to generate a nested module. Together with outputModuleDir of src the final module will be at src/Acme/Icons.elm (using \ on Windows)

Using the new Module in your code

Make sure to add elm/svg and elm/virtual-dom to your elm.json

elm install elm/svg
elm install elm/virtual-dom

Then in your Elm use your SVGs by importing the generated module.

-- the imports are named after the original file names of the SVGs
-- burger-menu.svg will result in an burgerMenu function
import Icons (burgerMenu, someOtherIcon)

view model =
  div []
    [ burgerMenu []
    , someOtherIcon []
    ]

Dealing with the generated file (the recommended way)

It's recommended to put the generated files into the elm-stuff directory, where it is likely ignored git by anyway. It works well and you'll never really see the generated files while coding.

  1. Set the outputModuleDir to elm-stuff/elm-svg-modules
  2. Add elm-stuff/elm-svg-modules to the source-directories in your project's elm.json

Dealing with the generated file (the other way)

If for some reason you do not want to have the generated file in elm-stuff, you can just put them somewhere else, i.e. your src folder and add them to your .gitignore.

  1. Set the outputModuleDir to src
  2. Add src/Icons.elm (or however the file is named in your configuration) to the .gitignore in your project.

How it works

When the Elm module is processed by parcel this plugin uses its config to find all the svg files and generates one Elm module per item in the config array.

Credits

This plugin uses the awesome svg2elm package under the hood.

Also lot's of inspiration for this plugin came from this repo, which did the same as a parcel v1 plugin.