From decedb079d2d844129271dfc28d33353ce16aa84 Mon Sep 17 00:00:00 2001 From: Yamagishi Kazutoshi Date: Wed, 29 Apr 2020 05:18:42 +0900 Subject: [PATCH] fix(v2): add support esModule to lqip-loader --- packages/lqip-loader/src/index.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/lqip-loader/src/index.js b/packages/lqip-loader/src/index.js index 78d61ee724c3..c8b13685bd9d 100644 --- a/packages/lqip-loader/src/index.js +++ b/packages/lqip-loader/src/index.js @@ -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 = [];