From bccfe6d4fd0519b67ffc9e58b6ce5c3b9a365ffb Mon Sep 17 00:00:00 2001 From: Kael Date: Sat, 6 Feb 2021 00:18:22 +1100 Subject: [PATCH] fix: support cjs image modules fixes #169 --- dev4/webpack.config.js | 2 +- progressive-loader/loader.js | 8 ++++---- progressive-loader/module.js | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dev4/webpack.config.js b/dev4/webpack.config.js index 4fb16eb..39a8e4c 100644 --- a/dev4/webpack.config.js +++ b/dev4/webpack.config.js @@ -53,7 +53,7 @@ module.exports = { { test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)(\?.*)?$/, loader: 'url-loader', - options: { limit: 8000 } + options: { limit: 1024 } } ] }, diff --git a/progressive-loader/loader.js b/progressive-loader/loader.js index 7874125..2af10f8 100644 --- a/progressive-loader/loader.js +++ b/progressive-loader/loader.js @@ -18,10 +18,10 @@ module.exports = function loader(contentBuffer) { } /** @see https://github.com/zouhir/lqip-loader */ - const contentIsUrlExport = /^export default "data:(.*)base64,(.*)/.test( + const contentIsUrlExport = /^(export default|module.exports =) "data:(.*)base64,(.*)/.test( content ) - const contentIsFileExport = /^export default (.*)/.test(content) + const contentIsFileExport = /^(export default|module.exports =) (.*)/.test(content) let source = '' if (contentIsUrlExport) { @@ -32,7 +32,7 @@ module.exports = function loader(contentBuffer) { const fileLoader = require('file-loader') content = fileLoader.call(this, contentBuffer) } - source = content.match(/^export default (.*);/)[1] + source = content.match(/^(?:export default|module.exports =) (.*);/)[1] } function createModule ({ data, info, type }) { @@ -42,7 +42,7 @@ module.exports = function loader(contentBuffer) { } callback( null, - `export default {src:${source},` + JSON.stringify(result).slice(1) + `module.exports = {src:${source},` + JSON.stringify(result).slice(1) ) } diff --git a/progressive-loader/module.js b/progressive-loader/module.js index 424fed4..02be3b3 100644 --- a/progressive-loader/module.js +++ b/progressive-loader/module.js @@ -29,7 +29,7 @@ function urlToRequire(url) { const secondChar = url.charAt(1) url = url.slice(secondChar === '/' ? 2 : 1) } - return `require("${url}?vuetify-preload").default` + return `require("${url}?vuetify-preload")` } else { return `"${url}"` }