From 08dd5448489a5ec8fc412762b0fe5206e4b955bf Mon Sep 17 00:00:00 2001 From: anikethsaha Date: Thu, 12 Dec 2019 01:16:22 +0530 Subject: [PATCH] chore(test): added tests for additional plugin feat --- package.json | 7 ++- test/webpack-additional.config.js | 88 +++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 test/webpack-additional.config.js diff --git a/package.json b/package.json index 63e4f4f..06d08c2 100644 --- a/package.json +++ b/package.json @@ -13,23 +13,26 @@ "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:webpack-additional": "npm install -q webpack@4.x webpack-cli@3.3.10 imagemin-jpegtran && npm run test:clean && webpack --config test/webpack-additional.config.js", "test:clean": "rimraf test/public/assets", "test": "npm run test:webpack1 && npm run test:webpack2 && npm run test:webpack3 && npm run test:webpack4" }, "dependencies": { "imagemin": "^5.3.1", "imagemin-gifsicle": "^5.2.0", + "imagemin-jpegtran": "^6.0.0", "imagemin-mozjpeg": "^7.0.0", "imagemin-optipng": "^5.2.1", "imagemin-pngquant": "^5.1.0", "imagemin-svgo": "^6.0.0", "imagemin-webp": "^4.1.0", "loader-utils": "^1.1.0", - "object-assign": "^4.1.1" + "object-assign": "^4.1.1", + "webpack": "^4.41.2" }, "devDependencies": { "file-loader": "^1.1.11", "rimraf": "^2.6.2", - "webpack-cli": "^2.1.3" + "webpack-cli": "^3.3.10" } } diff --git a/test/webpack-additional.config.js b/test/webpack-additional.config.js new file mode 100644 index 0000000..58a589b --- /dev/null +++ b/test/webpack-additional.config.js @@ -0,0 +1,88 @@ +'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 + } + ] + }, + additionalPlugins: [ + { + plugin: 'imagemin-jpegtran', + options: { + progressive: true + } + } + ], + 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 + ] + } + ] + } + } +];