Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

modernizr-loader

peerigon24kMIT1.0.1

use modernizr with webpack easily

modernizr, webpack, loader

readme

modernizr-loader for webpack

Build Status devDependency Status peerDependency Status

Installation

$ npm install --save-dev modernizr modernizr-loader

Initialization

You have to create a .modernizrrc configuration file and put your modernizr stuff in it. Like so

// .modernizrrc
{
  "minify": true,
  "options": [
    "setClasses"
  ],
  "feature-detects": []
}

Full list of supported "options" and "feature-detects" can be found in Modernizr config-all.json.

Webpack config

Documentation: Using loaders

Put the following code to your webpack config file:

module.exports = {
  module: {
    loaders: [
      {
        test: /\.modernizrrc.js$/,
        loader: "modernizr"
      },
      {
        test: /\.modernizrrc(\.json)?$/,
        loader: "modernizr!json"
      }
    ]
  },
  resolve: {
    alias: {
      modernizr$: path.resolve(__dirname, "path/to/.modernizrrc")
    }
  }
}

Usage

Now you are able to import your custom Modernizr build as a module throughout your application like so:

import Modernizr from 'modernizr';

if (!Modernizr.promises) {
    // ...
}

See the Modernizr documentation for all available options.

Contribution

Don't hesitate to create a pull request. Every contribution is appreciated.

changelog

1.0.1

  • Fix: Modernizr tests not working properly if window is undefined (#25)

1.0.0

  • Don't attach Modernizr to window anymore
  • Allow using a JavaScript file for configuration

Important notice: If you previously relied on a JSON configuration file, make sure to pass your configuration to the json-loader before passing it to the modernizr-loader (we upgraded the example in the README). You don't need to do this with webpack 2, because it can require JSON by itself.

0.0.5

0.0.4

  • Expose Modernizr as a module 5423888