Skip to content
This repository was archived by the owner on Mar 17, 2023. It is now read-only.

Commit ac03972

Browse files
author
Daniel Schmidt
committed
add support for webpack 4
We currently already have support for webpack4, so I just needed to add some tests.
1 parent b30e0fb commit ac03972

File tree

2 files changed

+82
-3
lines changed

2 files changed

+82
-3
lines changed

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
"test:webpack1": "npm install -q [email protected] && npm run test:clean && webpack --config test/webpack1.config.js",
1313
"test:webpack2": "npm install -q [email protected] && npm run test:clean && webpack --config test/webpack2.config.js",
1414
"test:webpack3": "npm install -q [email protected] && npm run test:clean && webpack --config test/webpack2.config.js",
15+
"test:webpack4": "npm install -q [email protected] webpack-cli && npm run test:clean && webpack --config test/webpack4.config.js",
1516
"test:clean": "rm -rf test/public/assets",
16-
"test": "npm run test:webpack1 && npm run test:webpack2 && npm run test:webpack3"
17+
"test": "npm run test:webpack1 && npm run test:webpack2 && npm run test:webpack3 && npm run test:webpack4"
1718
},
1819
"dependencies": {
1920
"imagemin": "^5.2.2",
@@ -24,9 +25,10 @@
2425
"imagemin-svgo": "^6.0.0",
2526
"imagemin-webp": "^4.0.0",
2627
"loader-utils": "^1.1.0",
27-
"object-assign": "^4.1.1"
28+
"object-assign": "^4.1.1",
29+
"webpack-cli": "^2.1.3"
2830
},
2931
"devDependencies": {
30-
"file-loader": "^0.10.1"
32+
"file-loader": "^1.1.11"
3133
}
3234
}

test/webpack4.config.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
'use strict';
2+
var path = require('path');
3+
var webpack = require('webpack');
4+
5+
var assetsPath = path.join(__dirname, 'public/assets');
6+
7+
var loaderOptions = {
8+
mozjpeg: {
9+
quality: 65
10+
},
11+
pngquant:{
12+
quality: "65-90",
13+
speed: 4
14+
},
15+
svgo:{
16+
plugins: [
17+
{
18+
removeViewBox: false
19+
},
20+
{
21+
removeEmptyAttrs: false
22+
}
23+
]
24+
},
25+
gifsicle: {
26+
optimizationLevel: 7,
27+
interlaced: false
28+
},
29+
optipng: {
30+
optimizationLevel: 7,
31+
interlaced: false
32+
},
33+
webp: {
34+
quality: 75
35+
}
36+
}
37+
38+
var fileLoaderOptions = {
39+
hash: 'sha512',
40+
digest: 'hex',
41+
name: '[hash].[ext]'
42+
}
43+
44+
module.exports = [
45+
{
46+
mode: 'production',
47+
entry: './test/app.js',
48+
output: {
49+
path: assetsPath,
50+
filename: 'app.[hash].js'
51+
},
52+
module: {
53+
rules: [{
54+
test: /.*\.(gif|png|jpe?g|svg|webp)$/i,
55+
use: [
56+
{
57+
loader: 'file-loader',
58+
options: fileLoaderOptions
59+
},
60+
{
61+
loader: require.resolve('../'),
62+
options: loaderOptions
63+
}
64+
]
65+
}, {
66+
test: /\.bmp$/i,
67+
use: [
68+
{
69+
loader: 'file-loader',
70+
options: fileLoaderOptions
71+
},
72+
require.resolve('../') // loaderUtils.getOptions() returns null for this one
73+
]
74+
}]
75+
}
76+
}
77+
];

0 commit comments

Comments
 (0)