mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-23 22:17:00 +02:00
fix(v2): add support for esModule to lqip-loader (#2693)
This commit is contained in:
parent
daafd2f0cc
commit
5ea263d272
1 changed files with 10 additions and 4 deletions
|
@ -20,23 +20,29 @@ module.exports = function (contentBuffer) {
|
||||||
config.palette = 'palette' in config ? config.palette : false;
|
config.palette = 'palette' in config ? config.palette : false;
|
||||||
|
|
||||||
let content = contentBuffer.toString('utf8');
|
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,
|
content,
|
||||||
);
|
);
|
||||||
const contentIsFileExport = /^module.exports = (.*)/.test(content);
|
|
||||||
|
|
||||||
let source = '';
|
let source = '';
|
||||||
const SOURCE_CHUNK = 1;
|
const SOURCE_CHUNK = 1;
|
||||||
|
|
||||||
if (contentIsUrlExport) {
|
if (contentIsUrlExport) {
|
||||||
source = content.match(/^module.exports = (.*)/)[SOURCE_CHUNK];
|
source = content.match(/^(?:export default|module.exports =) (.*)/)[
|
||||||
|
SOURCE_CHUNK
|
||||||
|
];
|
||||||
} else {
|
} else {
|
||||||
if (!contentIsFileExport) {
|
if (!contentIsFileExport) {
|
||||||
// eslint-disable-next-line global-require
|
// eslint-disable-next-line global-require
|
||||||
const fileLoader = require('file-loader');
|
const fileLoader = require('file-loader');
|
||||||
content = fileLoader.call(this, contentBuffer);
|
content = fileLoader.call(this, contentBuffer);
|
||||||
}
|
}
|
||||||
source = content.match(/^module.exports = (.*);/)[SOURCE_CHUNK];
|
source = content.match(/^(?:export default|module.exports =) (.*);/)[
|
||||||
|
SOURCE_CHUNK
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
const outputPromises = [];
|
const outputPromises = [];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue