Skip to content

Commit

Permalink
fix(v2): add support for esModule to lqip-loader (#2693)
Browse files Browse the repository at this point in the history
  • Loading branch information
ykzts authored May 17, 2020
1 parent daafd2f commit 5ea263d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/lqip-loader/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,29 @@ module.exports = function (contentBuffer) {
config.palette = 'palette' in config ? config.palette : false;

let content = contentBuffer.toString('utf8');
const contentIsUrlExport = /^module.exports = "data:(.*)base64,(.*)/.test(
const contentIsUrlExport = /^(?:export default|module.exports =) "data:(.*)base64,(.*)/.test(
content,
);
const contentIsFileExport = /^(?:export default|module.exports =) (.*)/.test(
content,
);
const contentIsFileExport = /^module.exports = (.*)/.test(content);

let source = '';
const SOURCE_CHUNK = 1;

if (contentIsUrlExport) {
source = content.match(/^module.exports = (.*)/)[SOURCE_CHUNK];
source = content.match(/^(?:export default|module.exports =) (.*)/)[
SOURCE_CHUNK
];
} else {
if (!contentIsFileExport) {
// eslint-disable-next-line global-require
const fileLoader = require('file-loader');
content = fileLoader.call(this, contentBuffer);
}
source = content.match(/^module.exports = (.*);/)[SOURCE_CHUNK];
source = content.match(/^(?:export default|module.exports =) (.*);/)[
SOURCE_CHUNK
];
}

const outputPromises = [];
Expand Down

0 comments on commit 5ea263d

Please sign in to comment.