@docusaurus/lqip-loader 4.0.0-canary-6928 → 4.0.0-canary-6929

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +10 -19
  2. package/lib/index.js +3 -5
  3. package/package.json +2 -4
package/README.md CHANGED
@@ -16,31 +16,22 @@ Generating Base64 for a jpeg image imported in your JS bundle:
16
16
 
17
17
  ### `webpack.config.js`
18
18
 
19
+ The LQIP loader must be chained after a loader exporting the image URL as a JS module, such as [`@docusaurus/responsive-loader`](https://github.com/slorber/responsive-loader):
20
+
19
21
  ```js
20
22
  {
21
- // OPTION A: default file-loader fallback
22
- test: /\.jpe?g$/,
23
- loaders: [
24
- {
25
- loader: '@docusaurus/lqip-loader',
26
- options: {
27
- path: '/media', // your image going to be in media folder in the output dir
28
- name: '[name].[ext]', // you can use [contenthash].[ext] too if you wish,
29
- }
30
- }
31
- ]
32
-
33
- // OPTION B: Chained with your own url-loader or file-loader
34
23
  test: /\.(png|jpe?g)$/,
35
- loaders: [
24
+ // Loaders produce a JS module, not an asset
25
+ type: 'javascript/auto',
26
+ use: [
36
27
  '@docusaurus/lqip-loader',
37
28
  {
38
- loader: 'url-loader',
29
+ loader: '@docusaurus/responsive-loader',
39
30
  options: {
40
- limit: 8000
41
- }
42
- }
43
- ]
31
+ adapter: require('@docusaurus/responsive-loader/sharp'),
32
+ },
33
+ },
34
+ ],
44
35
  }
45
36
  ```
46
37
 
package/lib/index.js CHANGED
@@ -13,7 +13,7 @@ async function lqipLoader(contentBuffer) {
13
13
  this.cacheable();
14
14
  const callback = this.async();
15
15
  const imgPath = this.resourcePath;
16
- let content = contentBuffer.toString('utf8');
16
+ const content = contentBuffer.toString('utf8');
17
17
  const contentIsUrlExport = /^(?:export default|module.exports =) "data:.*base64,.*/.test(content);
18
18
  const contentIsFileExport = /^(?:export default|module.exports =) .*/.test(content);
19
19
  let source;
@@ -22,10 +22,8 @@ async function lqipLoader(contentBuffer) {
22
22
  }
23
23
  else {
24
24
  if (!contentIsFileExport) {
25
- // eslint-disable-next-line @typescript-eslint/no-require-imports
26
- const fileLoader = require('file-loader');
27
- // @ts-expect-error: type is a bit unwieldy...
28
- content = fileLoader.call(this, contentBuffer);
25
+ callback(new Error(`The LQIP loader must be chained after a loader exporting the image URL, such as @docusaurus/responsive-loader. Image path: ${imgPath}`));
26
+ return;
29
27
  }
30
28
  source = content.match(/^(?:export default|module.exports =) (?<source>.*);/).groups.source;
31
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/lqip-loader",
3
- "version": "4.0.0-canary-6928",
3
+ "version": "4.0.0-canary-6929",
4
4
  "description": "Low Quality Image Placeholders (LQIP) loader for webpack.",
5
5
  "main": "lib/index.js",
6
6
  "publishConfig": {
@@ -13,8 +13,7 @@
13
13
  },
14
14
  "license": "MIT",
15
15
  "dependencies": {
16
- "@docusaurus/logger": "4.0.0-canary-6928",
17
- "file-loader": "^6.2.0",
16
+ "@docusaurus/logger": "4.0.0-canary-6929",
18
17
  "sharp": "^0.35.1",
19
18
  "tslib": "^2.8.1"
20
19
  },
@@ -22,7 +21,6 @@
22
21
  "node": ">=24.21"
23
22
  },
24
23
  "devDependencies": {
25
- "@types/file-loader": "^5.0.4",
26
24
  "webpack": "^5.111.0"
27
25
  },
28
26
  "scripts": {