Giter Site home page Giter Site logo

dword-design / nuxt-modernizr Goto Github PK

View Code? Open in Web Editor NEW
11.0 1.0 0.0 3.04 MB

Adds a Modernizr build to your Nuxt.js app.

License: Other

JavaScript 97.95% Shell 2.05%
modernizr nuxt nuxtjs nuxt-module nuxtjs-module feature-detection browser-detection frontend javascript webdevelopment

nuxt-modernizr's Introduction

nuxt-modernizr

npm version Linux macOS Windows compatible Build status Coverage status Dependency status Renovate enabled
Open in Gitpod Buy Me a Coffee PayPal Patreon

Adds a Modernizr build to your Nuxt.js app.

Install

# npm
$ npx nuxi module add nuxt-modernizr

# Yarn
$ yarn nuxi module add nuxt-modernizr

Usage

Add the module to your Nuxt.js modules list in nuxt.config.js:

export default {
  ...
  modules: [
    ['nuxt-modernizr', {
      'feature-detects': ['css/scrollbars', 'css/overflow-scrolling'],
      options: ['setClasses'],
    }],
  ],
}

Access the Modernizr variable in your app:

if (process.client && Modernizr.cssscrollbar) {
  ...
}

Note that Modernizr only works client-side, so don't forget to check for client-side via process.client. If you use a linter that restricts global variables, you can use window.Modernizr instead.

Because we use a global variable here, it can also be accessed in contributed components that need to access Modernizr. The only requirement is that this module is included in the build.

Options

This module passes the options down to the modernizr NPM package. Please refer to this for the available options.

Directly:

export default {
  ...
  modules: [
    ['nuxt-modernizr', {
      'feature-detects': ['css/scrollbars', 'css/overflow-scrolling'],
      options: ['setClasses'],
    }],
  ],
}

Top-level:

export default {
  ...
  modules: [
    'nuxt-modernizr',
  ],
  modernizr: {
    'feature-detects': ['css/scrollbars', 'css/overflow-scrolling'],
    options: ['setClasses'],
  },
}

Contribute

Are you missing something or want to contribute? Feel free to file an issue or a pull request! ⚙️

Support

Hey, I am Sebastian Landwehr, a freelance web developer, and I love developing web apps and open source packages. If you want to support me so that I can keep packages up to date and build more helpful tools, you can donate here:

Buy Me a Coffee  If you want to send me a one time donation. The coffee is pretty good 😊.
PayPal  Also for one time donations if you like PayPal.
Patreon  Here you can support me regularly, which is great so I can steadily work on projects.

Thanks a lot for your support! ❤️

See also

  • nuxt-mail: Adds email sending capability to a Nuxt.js app. Adds a server route, an injected variable, and uses nodemailer to send emails.
  • nuxt-route-meta: Adds Nuxt page data to route meta at build time.
  • nuxt-mermaid-string: Embed a Mermaid diagram in a Nuxt.js app by providing its diagram string.
  • nuxt-content-git: Additional module for @nuxt/content that replaces or adds createdAt and updatedAt dates based on the git history.
  • nuxt-babel-runtime: Nuxt CLI that supports babel. Inspired by @nuxt/typescript-runtime.

License

MIT License © Sebastian Landwehr

nuxt-modernizr's People

Contributors

actions-user avatar dword-design avatar dword-design-honestly avatar github-actions[bot] avatar renovate-bot avatar renovate[bot] avatar semantic-release-bot avatar test123456789012345 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

nuxt-modernizr's Issues

no-js logic (set classes) got a conflict with head options

Hi, just started to use this package and it seems quite nice.
But I noticed a isse on my code and not sure if depending on my code, this package or nuxt logic itself and I would liek to ask some help.

Here a description of my issue (steps):

  1. I've installed the package following the documentation. All is fine.

  2. Because I want to use the "no-js / js class" logic for setting a class on html element (the "setClasses" option from Modernizr itself), I did the following: set the option as shown on package documentation, then added 'no-js' class to the html tag from nuxt config file, as following:

``
head: {
...

htmlAttrs: {

  class: 'no-js',

},

...

}
``

Also here all was fine.
Page is loaded, and class "no-js" added on DOM (by Nuxt htmlAttrs). Then JS on client is loaded, also Modernizr, and class "no-js" is changed to class "js" by Modernizr.

  1. Then here the issue: on a page (call this page "subpage") I've decided to overwrite, in the page itself by the method "head", the title of the page.
    This is working, but as side effects I've noticed that when I navigate from the homepage to the "subpage", the no-js/js class set by modernizr is kind of "reset".

My possible explanation
After several tests, it seems that the setClasses logic is kind of 'reset' any time in a Vue page or Vue component I set the "head" property and try to overwrite ANY options in it (at page change).

In this way the Modernizr "setClasses" logic (what I use to call "no-js / js class trick") seems crashing or at least reset to the value set in nuxt config file (".no-js").

My question
Anyone experienced this issue? is this an issue related to this package, or to Nuxt logic in general?
Could anyone support me on this issue?

I've also set a test repo where I've set some basic code as documentation here:
https://github.com/valeriosillari/nuxt-modernizr-test

Error: 'Failed to resolve import...'

When tryin to follow the instructions of the readme.md (in nuxt 3), this error occurs:

Failed to resolve import "/Users/alexanderhorner/Documents/GitHub.nosync/wgg-homepage/.nuxt/Users/alexanderhorner/Documents/GitHub.nosync/wgg-homepage/.nuxt/nuxt-modernizr/plugin.js" from "virtual:nuxt:/Users/alexanderhorner/Documents/GitHub.nosync/wgg-homepage/.nuxt/plugins/client.mjs". Does the file exist?

package.json:

{
  "private": true,
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "generate": "nuxt generate",
    "preview": "nuxt preview"
  },
  "devDependencies": {
    "@nuxt/content": "^2.1.0",
    "nuxt": "^3.0.0-rc.10",
    "sass": "^1.54.9"
  },
  "dependencies": {
    "@nuxtjs/google-fonts": "^3.0.0-0",
    "flickity": "^3.0.0",
    "isotope-layout": "^3.0.6",
    "nuxt-modernizr": "^2.0.10",
    "reading-time": "^1.5.0",
    "vue-stripe-menu": "^2.1.1",
    "vue3-lazyload": "^0.3.6"
  }
}

Feature request: add TS types for Modernizr and all its properties

In TypeScript projects the TS compiler will complain about the variable Modernizr not existing on the Window object or globally. It can be solved by adding types manually*, but it would be helpful if this would module provide the types out of the box.

Good to know that community type definitions for Modernizr exist, but do not add them to window (if I am not mistaken): https://www.npmjs.com/package/@types/modernizr

(*) Note: I manually typed the test result for the <details> element as follows:

declare global {
  interface Window {
    Modernizr: {
      details: boolean;
    };
  }
};

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: Cannot find preset's package (github>whitesource/merge-confidence:beta)

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.