Skip to content

Commit ec12580

Browse files
committed
Bugfix: jpeg extension
1 parent 8e0602f commit ec12580

File tree

8 files changed

+29
-25
lines changed

8 files changed

+29
-25
lines changed

src/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as path from "path"
22
import type { Options, MimeType, LoaderContext, ImageOptions, CacheOptions } from "./types"
33
const version = "3"
4+
45
enum MIMES {
56
jpg = "image/jpeg",
67
jpeg = "image/jpeg",
@@ -52,6 +53,7 @@ function parseOptions(loaderContext: LoaderContext, options: Options): ParsedOpt
5253
ext = path.extname(loaderContext.resourcePath).replace(/\./, "")
5354
switch (ext) {
5455
case "jpg":
56+
case "jpeg":
5557
case "png":
5658
case "webp":
5759
case "avif":

test/cache/build/__snapshots__/test.js.snap

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`disable 1`] = `
4-
Object {
5-
"default": Object {
6-
"images": Array [
7-
Object {
8-
"height": 100,
9-
"path": "foobar/d65e7eabf402c163ee9e87493c5b07af-100.jpg",
10-
"width": 100,
11-
},
12-
],
13-
"src": "foobar/d65e7eabf402c163ee9e87493c5b07af-100.jpg",
14-
"srcSet": "foobar/d65e7eabf402c163ee9e87493c5b07af-100.jpg",
15-
"toString": [Function],
16-
},
17-
}
18-
`;
19-
203
exports[`jpg to webp 1`] = `
214
Object {
225
"default": Object {

test/cache/index.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ test("with size defined in webpack.config.js", () => {
4141
expect(multi).toMatchSnapshot()
4242
})
4343

44-
test("disable", () => {
45-
const multi = require("../cat-1000.jpg?disable")
46-
expect(multi).toMatchSnapshot()
47-
})
48-
4944
test("output should be relative to context", () => {
5045
const multi = require("../cat-1000.jpg?name=[path][hash]-[width]x[height].[ext]&context=./")
5146
expect(multi).toMatchSnapshot()

test/cat-1000copy.jpeg

53 KB
Loading

test/sharp/build/__snapshots__/test.js.snap

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,25 @@ Object {
3636
}
3737
`;
3838

39+
exports[`jpeg extension 1`] = `
40+
Object {
41+
"default": Object {
42+
"height": 395,
43+
"images": Array [
44+
Object {
45+
"height": 395,
46+
"path": "foobar/f32ecdef2ffef2786a6499ee57bfe2d1-439.jpeg",
47+
"width": 439,
48+
},
49+
],
50+
"src": "foobar/f32ecdef2ffef2786a6499ee57bfe2d1-439.jpeg",
51+
"srcSet": "foobar/f32ecdef2ffef2786a6499ee57bfe2d1-439.jpeg 439w",
52+
"toString": [Function],
53+
"width": 439,
54+
},
55+
}
56+
`;
57+
3958
exports[`jpg to webp 1`] = `
4059
Object {
4160
"default": Object {
Loading

test/sharp/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
test("jpeg extension", () => {
2+
const output = require("../cat-1000copy.jpeg?size=439")
3+
expect(output).toMatchSnapshot()
4+
})
5+
16
test("png to avif", () => {
27
const output = require("../cat-transparent.png?format=avif&size=777")
38
expect(output).toMatchSnapshot()

test/sharp/webpack.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const path = require("path");
1+
const path = require("path")
22

33
module.exports = {
44
mode: "development",
@@ -18,7 +18,7 @@ module.exports = {
1818
},
1919
},
2020
{
21-
test: /\.(png|jpg)$/,
21+
test: /\.(png|jpe?g)$/,
2222
loader: require.resolve("../../lib/index"),
2323
options: {
2424
sizes: [500, 750, 1000],
@@ -34,4 +34,4 @@ module.exports = {
3434
filename: "test.js",
3535
},
3636
target: "node",
37-
};
37+
}

0 commit comments

Comments
 (0)