Code Monkey home page Code Monkey logo

laravel-mix-modernizr's Introduction

Laravel Mix Modernizr

Latest Version on NPM npm Software License

This extension adds support for Modernizr to Laravel Mix by using the webpack-modernizr-loader.

It allows you to easily configure, create and manage custom Modernizr builds in your Laravel Mix project.

Installation

npm i -D laravel-mix-modernizr

Basic Usage

Require and use the extension inside your webpack.mix.js like this:

/* 
 * webpack.mix.js
 */

const mix = require('laravel-mix');
require('laravel-mix-modernizr');

mix
  .js('app.js', 'dist')
  .modernizr()

This will use or create a .modernizrrc file in your project root and make the corresponding custom build instantly accessible via a Modernizr global identifier when you run Mix.

Now, set the Modernizr configurations to your liking, for example:

/* 
 * .modernizrrc
 */

module.exports = {
  "classPrefix": "supports-",
  "options": [
    "addTest",
  ],
  "feature-detects": [
    "test/css/flexbox",
    "test/css/transforms"
  ]
};

For more information on how to configure Modernizr please refer to their documentation.

You can now use the resulting Modernizr build in your project:

/* 
 * app.js
 */

// Includes the custom Modernizr build based on the configurations set in .modernizrrc
require('Modernizr');

If you want to get fancy with Modernizr (i.e. access Modernizr), you don't even need to explicitly require it. Just start using it. A behind-the-scenes call of mix.autoload() will handle the import automatically.

/* 
 * app.js
 */

// Once accessed, the Modernizr build will be imported automatically
Modernizr.addTest(/* ... */);

Advanced Usage

You can also use non-standard configuration file locations and custom global identifiers to maintain multiple different Modernizr builds in your project:

/* 
 * webpack.mix.js
 */

const mix = require('laravel-mix');
require('laravel-mix-modernizr');

mix
  .js('app.js', 'dist')
  .modernizr({
    SpecialModernizr: '.special-modernizrrc', // Creates a build based on .special-modernizrrc
    AnotherModernizr: 'some/path/modernizrrc.js' // Creates a build based on some/path/modernizrrc.js
  })

You now have access to the SpecialModernizr and AnotherModernizr global identifiers instead of the default Modernizr. Use them just like in the basic example.

laravel-mix-modernizr's People

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

laravel-mix-modernizr's Issues

Question: Does this support extract ?

I am trying this

let mix = require('laravel-mix');
require('laravel-mix-modernizr');

mix.webpackConfig({
    devtool: 'source-map'
});

mix.coffee(['src/resources/coffee/app.coffee'], 'js/app.js').modernizr().extract([
    'bootstrap',
    'popper.js',
    'jquery',
    'lodash',
    'jquery.fancytree',
    'js-base64',
    'lazyload',
    'highlight.js',
    'mediaelement',
    'Modernizr'
]);

But i find modernizr in app.js and vendor.js

[webpack-cli] ReferenceError: path is not defined

Hi there! I enjoy using your package. Thanks a lot for that. However since upgrading to Laravel Mix 6 I can't get it to compile anymore. npm run dev greets me with:

[webpack-cli] ReferenceError: path is not defined
    at /Users/robdekort/Sites/statamic-peak/node_modules/laravel-mix-modernizr/index.js:49:17
    at Array.forEach (<anonymous>)
    at Modernizr.register (/Users/robdekort/Sites/statamic-peak/node_modules/laravel-mix-modernizr/index.js:34:28)
    at Object.components.<computed> [as modernizr] (/Users/robdekort/Sites/statamic-peak/node_modules/laravel-mix/src/components/ComponentRegistrar.js:118:53)
    at Object.<anonymous> (/Users/robdekort/Sites/statamic-peak/webpack.mix.js:9:6)
    at Module._compile (/Users/robdekort/Sites/statamic-peak/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1112:10)
    at Module.load (node:internal/modules/cjs/loader:948:32)
    at Function.Module._load (node:internal/modules/cjs/loader:789:14)
    at Module.require (node:internal/modules/cjs/loader:972:19)
npm ERR! code 2
npm ERR! path /Users/robdekort/Sites/statamic-peak
npm ERR! command failed
npm ERR! command sh -c webpack --progress '--config=/Users/robdekort/Sites/statamic-peak/node_modules/laravel-mix/setup/webpack.config.js'

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/robdekort/.npm/_logs/2020-12-28T12_27_03_144Z-debug.log
npm ERR! code 2
npm ERR! path /Users/robdekort/Sites/statamic-peak
npm ERR! command failed
npm ERR! command sh -c mix

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/robdekort/.npm/_logs/2020-12-28T12_27_03_176Z-debug.log

The build does compile without using laravel-mix-modernizr. I get the feeling this package might need to be made compatible with Laravel Mix 6. Do you maybe have any thoughts on this?

Change modernizr loader

So far as I can tell, webpack-modernizr-loader is not being supported. If you install this module and then let it handle installing webpack-modernizr-loader, everything will install and work fine, but subsequent runs of npm install from scratch (or npm ci) will not be able to resolve their dependencies.

Probably ought to move to a supported Modernizr loader, such as this one.

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.