how to use Modernizr in VueJS Webpack project

牧云@^-^@ 提交于 2020-01-14 22:51:16

问题


Does anyone have a simple tutorial to bundle and use Modernizr in a VueJs Webpack project?

I use the default Webpack project of VueJS with monofile components. I want it all bundled.

For precision i want to use inputtypes.date in a majority of forms and avoid display vuetify date picker when on mobile browser with date picker support.


回答1:


I have not used modernizr, but based on my experience using webpack, i think you can use existing modernizr loaders, i.e webpack-modernizr-loader

As its docs says your can use .modernizrrc.js config file, for example:

"use strict";

module.exports = {
  options: [
    "setClasses"
  ],
  "feature-detects": [
    "inputtypes"
  ]
};

adding webpack rule and alias to your webpack.config.js (note you need point to right place, where config file stored in alias path.resolve...):

const path = require('path');

module.exports = {
  module: {
    rules: [
      {
        loader: "webpack-modernizr-loader",
        test: /\.modernizrrc\.js$/
      }
    ]
  },
  resolve: {
    alias: {
      modernizr$: path.resolve(__dirname, "/path/to/.modernizrrc.js")
    }
  }
}

then you can import your modernizr and use it like this:

import modernizr from 'modernizr';

if(modernizr.inputtypes.date) {
   ...
}


来源:https://stackoverflow.com/questions/49221027/how-to-use-modernizr-in-vuejs-webpack-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!