Comments (11)
Hey all,
our implementation looks like this and it's working pretty well:
module: {
rules: [
{
test: /\.modernizrrc$/,
use: ['modernizr-loader', 'json-loader'],
},
]
},
resolve: {
alias: {
modernizr$: path.resolve(__dirname, '.modernizrrc'),
}
}
I first tried the type: 'javascript/auto'
but it seems that it's not working if the file does not end with .json
? After that, I saw that webpack has an implemented type: 'json'
. But webpack also doesn't recognize the json file type (thows a compile error). Could it be that this is a webpack bug or that it's only working if the file ending is fitting to the declared type? Would be nice to be able to uninstall the json-loader.
module: {
rules: [
{
type: 'json',
test: /\.modernizrrc$/,
use: ['modernizr-loader'],
},
]
}
Thanks all! :-)
from modernizr-loader.
It would be really nice, if you would share the tweak with us!
from modernizr-loader.
hey all, is there any consensus for a workaround that works? I tried all of the above and they each resulted in my import Modernizr from 'modernizr'
being a string (a path to a static resource ala file-loader).
from modernizr-loader.
{
type: 'javascript/auto',
test: /modernizrrc(\.json)?$/,
use: ['expose-loader?Modernizr', 'modernizr-loader', 'json-loader'],
},
type: 'javascript/auto', << add this for json to load properly
from modernizr-loader.
@var-bp thanks for raising this issue. Would you mind providing a PR with a basic test case for webpack 4? We could use this as a starting point.
from modernizr-loader.
Done.
from modernizr-loader.
guys, any updates on this issue?
[edit] loader works with webpack 4 with a slight tweak of webpack config
from modernizr-loader.
Here is a snippet of what I have within my webpack.config.js file to get modernizr-loader working with Webpack 4.12.0
const webpack = require('webpack');
const path = require('path');
module: {
rules: [
{
test: /\.modernizrrc$/,
loader: "modernizr-loader!json-loader"
},
//Other rules to other packages here...
]
},
resolve: {
alias: {
modernizr$: path.resolve(__dirname, 'src/.modernizrrc')
}
}
I intentionally placed my .modernizrrc in my /src
folder. Its just a personal preference. But make sure you have the json-loader npm package installed.
My .modernizrrc file looks like the following, which loads classes on your <HTML>
element in the DOM.
{
"minify": true,
"options": [
"domPrefixes",
"hasEvent",
"testAllProps",
"testProp",
"html5shiv",
"setClasses"
],
"feature-detects": [
"history",
"flash",
"css/boxshadow",
"css/transitions",
"css/fontface",
"css/gradients",
"css/mediaqueries",
"es6/promises",
"forcetouch"
]
}
And for fun, I also added some conditional logic for modernizr in my custom JavaScript file, which also executes...
"use strict";
import Modernizr from 'modernizr';
var detects = {
'hasjquery': 'jQuery' in window,
'itswednesday': function() {
var d = new Date();
return d.getDay() === 3;
}
}
Modernizr.addTest(detects);
console.log("is jquery running? " + Modernizr.hasjquery);
console.log("is it Wednesday? " + Modernizr.itswednesday);
Hopefully this can save some headaches
from modernizr-loader.
the loaders are the same, except mine won't work without type: 'javascript/auto',
webpack 4 no longer use 'javascript/auto' as default type, and if the error encountered is of parsing of json, adding type: 'javascript/auto',
could solve the problem.
from modernizr-loader.
Everything works in @medialwerk configuration, except if I use a .modernizrrc*.json* file (explicit json extension) and update config accordingly. This is pretty strange
from modernizr-loader.
All works fine if we will be see on webpack documentation
module: {
rules: [{
test: /\.modernizrrc$/,
loader: 'modernizr-loader!json-loader',
}],
},
resolve: {
alias: {
modernizr$: path.resolve(__dirname, '.modernizrrc'),
}
}
from modernizr-loader.
Related Issues (20)
- the code `delete window.Modernizr` will throw an error in IE8 HOT 1
- Config from readme gives "path is not defined" HOT 2
- The modernizr-loader does not work with karma-webpack HOT 3
- Module build failed HOT 6
- Error in webpack Build HOT 26
- Error when parsing modernizrrc HOT 5
- Uncaught TypeError: _modernizr2.default.mq is not a function HOT 2
- json-loader is not required for webpack v2 and above HOT 1
- SyntaxError: Unexpected token : HOT 17
- specific chunk
- Pleas update npm docs!
- [Docs] Installing modernizr package
- detection of keyframes does not work HOT 1
- No Such File or Directory HOT 1
- Build errors: dependencies not found HOT 2
- Is this project deprecated? HOT 4
- Dependency not found
- Not working with webpack@^5.0.0 HOT 5
- modernizr-loader does not work with json5-loader@4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from modernizr-loader.