Skip to content

Commit

Permalink
Only apply css fix if nextjs builtin styling solution is used
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrilwanner committed Apr 2, 2020
1 parent c8a8715 commit befc894
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/loaders/img-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ const getHandledFilesRegex = (handledImageTypes) => {
return new RegExp(`\\.(${handledFiles.filter(Boolean).join('|')})$`, 'i');
};

/**
* Checks if a node module is installed in the current context
*
* @param {string} name - module name
* @returns {boolean}
*/
const isModuleInstalled = (name) => {
try {
require.resolve(name);

return true;
} catch (e) {
return false;
}
};

/**
* Checks if the plugin should get applied in CSS or not.
* Since next.js version 9.2, they already handle images out of the box so it should temporarily
Expand All @@ -84,6 +100,10 @@ const getHandledFilesRegex = (handledImageTypes) => {
*/
const applyInCss = () => {
try {
if (isModuleInstalled('@zeit/next-sass') || isModuleInstalled('@zeit/next-css')) {
return true;
}

const nextJsVersion = require('next/package.json').version; // eslint-disable-line import/no-unresolved

return compareVersions(nextJsVersion, '9.2.0') === -1;
Expand Down

0 comments on commit befc894

Please sign in to comment.