Code Monkey home page Code Monkey logo

aurelia-fontawesome-loader's Introduction

aurelia-fontawesome-loader

A webpack loader for aurelia-fontawesome

Why?

The loader makes it super easy to use the aurelia-fontawesome component with webpack. When the loader is configured properly you can simply write the following in your aurelia views:

<font-awesome-icon icon="coffee"></font-awesome-icon>

or

<font-awesome-icon icon.bind="['fab', 'microsoft']"></font-awesome-icon>

The coffee icon is automatically added as a dependency to the view and the icon is loaded when needed. This ensures that the final produced bundle/chunk only contains the icons that are actually used. Moreover, it also reduces the hassle of adding the icons one-by-one to the font-awesome library.

Installation

Install the loader with npm

$ npm i --save-dev aurelia-fontawesome-loader

How it Works

The loader transforms the html files with the following changes:

  • It adds a <require from="..."></require> for each icon it detects in <font-awesome-icon icon="..."></font-awesome-icon> to ensure that the icon becomes a dependency to the view.
  • It rewrites the icon property such that the fontawesome binding behavior is invoked which ensures that the icon is loaded before it is passed on to the icon property on the element. An example is <font-awesome-icon icon="coffee"></font-awesome-icon> which is rewritten to <font-awesome-icon icon.bind="'coffee' & fontawesome"></font-awesome-icon> See the sample app here for more examples on how the loader works.

Configuration

You can see the sample webpack configuration using the loader here. Two things needs to be configured for the loader to work propertly.

  1. The loader must be used for html files. It needs to run before the html-requires-loader which is included by default in the aurelia-webpack-plugin.
module: {
  rules: [
    {
      test: /\.html$/,
      use: [
        // The order of the loaders are important
        "html-loader",
        "aurelia-webpack-plugin/html-requires-loader",
        "aurelia-fontawesome-loader/loader"
      ]
    }
  ]
}

The loader resolves to the free icon set by default - you can use the loader with the pro option if you have that license. This is easiest done by setting the loader to "aurelia-fontawesome-loader/loader?pro".

  1. Tell the aurelia-webpack-plugin that it should not automatically insert the html-requires-loader:
plugins: [
  new AureliaPlugin({
    noHtmlLoader: true
  })
]
  1. Tell your aurelia app to include the loader binding behavior that brings in icons as needed. Do this by inserting the following in your code during aurelia boot
aurelia.use.plugin(PLATFORM.moduleName('aurelia-fontawesome-loader'))

aurelia-fontawesome-loader's People

Contributors

dependabot[bot] avatar rmja avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

aurelia-fontawesome-loader's Issues

does not work with html-loader 1.0.0

Hi rmja,

thanks for such a nice package.

When trying to upgrade to html-loader 1.0.0 aurelia-fontawesome-loader stopped working. It seems the problem is, that html-loader/lib/attributesParser is gone. Maybe you can have look into it? Thanks in advance :)

Greetings,
Thomas

Question: dynamic icon class?

In my use case I have a dynamic icon class within a component.

E.g. my variable is called iconClass and is bound to my component.

This doesn't quite fit into any of the examples you have shown

<font-awesome-icon icon.bind="iconClass"></font-awesome-icon>
Doesn't run the & fontawesome binding.

<font-awesome-icon icon.bind="iconClass & fontawesome"></font-awesome-icon>
Doesn't require the icon class.
Your example states "Require the icon manually and use it with the fontawesome binding behavior". Is it possible to do that dynamically, i.e. based on the bound variable iconClass?

I'm probably overlooking a simple a solution so appreciate your help!

Why do only brand icons require a 'fab' prefix but regular do not require 'far'?

I'm using Aurelia w/ Webpack and have set up aurelia-fontawesome-loader and aurelia-fontawesome. Everything is working, but was curious why some icons required a prefix, others required a lack of prefix, and some are optional.

For example, the commented out elements give errors because of prefixes.

<!--<font-awesome-icon icon="android"></font-awesome-icon>-->
<font-awesome-icon icon="grin-tongue-wink"></font-awesome-icon>
<font-awesome-icon icon="globe"></font-awesome-icon>

<font-awesome-icon icon.bind="['fab', 'android']"></font-awesome-icon>
<!--<font-awesome-icon icon.bind="['far', 'grin-tongue-wink']"></font-awesome-icon>-->
<font-awesome-icon icon.bind="['fas', 'globe']"></font-awesome-icon>

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.