From ac03972f4cdbd9ef24b192f0817665cd1b9fa241 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Mon, 14 May 2018 10:50:27 +0200 Subject: [PATCH] add support for webpack 4 We currently already have support for webpack4, so I just needed to add some tests. --- package.json | 8 +++-- test/webpack4.config.js | 77 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 test/webpack4.config.js diff --git a/package.json b/package.json index 9b7ad35..777e236 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,9 @@ "test:webpack1": "npm install -q webpack@1.x && npm run test:clean && webpack --config test/webpack1.config.js", "test:webpack2": "npm install -q webpack@2.x && npm run test:clean && webpack --config test/webpack2.config.js", "test:webpack3": "npm install -q webpack@3.x && npm run test:clean && webpack --config test/webpack2.config.js", + "test:webpack4": "npm install -q webpack@4.x webpack-cli && npm run test:clean && webpack --config test/webpack4.config.js", "test:clean": "rm -rf test/public/assets", - "test": "npm run test:webpack1 && npm run test:webpack2 && npm run test:webpack3" + "test": "npm run test:webpack1 && npm run test:webpack2 && npm run test:webpack3 && npm run test:webpack4" }, "dependencies": { "imagemin": "^5.2.2", @@ -24,9 +25,10 @@ "imagemin-svgo": "^6.0.0", "imagemin-webp": "^4.0.0", "loader-utils": "^1.1.0", - "object-assign": "^4.1.1" + "object-assign": "^4.1.1", + "webpack-cli": "^2.1.3" }, "devDependencies": { - "file-loader": "^0.10.1" + "file-loader": "^1.1.11" } } diff --git a/test/webpack4.config.js b/test/webpack4.config.js new file mode 100644 index 0000000..f4a284b --- /dev/null +++ b/test/webpack4.config.js @@ -0,0 +1,77 @@ +'use strict'; +var path = require('path'); +var webpack = require('webpack'); + +var assetsPath = path.join(__dirname, 'public/assets'); + +var loaderOptions = { + mozjpeg: { + quality: 65 + }, + pngquant:{ + quality: "65-90", + speed: 4 + }, + svgo:{ + plugins: [ + { + removeViewBox: false + }, + { + removeEmptyAttrs: false + } + ] + }, + gifsicle: { + optimizationLevel: 7, + interlaced: false + }, + optipng: { + optimizationLevel: 7, + interlaced: false + }, + webp: { + quality: 75 + } +} + +var fileLoaderOptions = { + hash: 'sha512', + digest: 'hex', + name: '[hash].[ext]' +} + +module.exports = [ + { + mode: 'production', + entry: './test/app.js', + output: { + path: assetsPath, + filename: 'app.[hash].js' + }, + module: { + rules: [{ + test: /.*\.(gif|png|jpe?g|svg|webp)$/i, + use: [ + { + loader: 'file-loader', + options: fileLoaderOptions + }, + { + loader: require.resolve('../'), + options: loaderOptions + } + ] + }, { + test: /\.bmp$/i, + use: [ + { + loader: 'file-loader', + options: fileLoaderOptions + }, + require.resolve('../') // loaderUtils.getOptions() returns null for this one + ] + }] + } + } +];