Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include the webpack Image Minimizer Plugin. #208

Open
wants to merge 2 commits into
base: v1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
},
"devDependencies": {
"eslint": "^7.32.0",
"image-minimizer-webpack-plugin": "^3.3.0",
"imagemin": "^8.0.1",
"imagemin-gifsicle": "^7.0.0",
"imagemin-jpegtran": "^7.0.0",
"imagemin-optipng": "^8.0.0",
"imagemin-svgo": "^10.0.1",
"jest": "^26.6.3",
"sass": "^1.51.0",
"typescript": "^4.6.3",
Expand Down
39 changes: 39 additions & 0 deletions src/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const RemoveEmptyScriptsPlugin = require( 'webpack-remove-empty-scripts' );
const SimpleBuildReportPlugin = require( 'simple-build-report-webpack-plugin' );
const TerserPlugin = require( 'terser-webpack-plugin' );
const CssMinimizerPlugin = require( 'css-minimizer-webpack-plugin' );
const ImageMinimizerPlugin = require( 'image-minimizer-webpack-plugin' );

const { applyFilters } = require( './helpers/filters' );

Expand Down Expand Up @@ -169,6 +170,44 @@ module.exports = {
*/
cssMinimizer: ( options = {} ) => new CssMinimizerPlugin( options ),

/**
* Image Minimizer Plugin.
*
* @returns {ImageMinimizerPlugin}
*/
imageMinimizer: () => {
// Svgo configuration.
// Reference: https://github.com/svg/svgo#configuration
// Example: https://github.com/svg/svgo#default-preset
const svgoConfig = {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
'removeViewBox': false,
},
},
},
],
};

return new ImageMinimizerPlugin( {
minimizer: {
implementation: ImageMinimizerPlugin.imageminMinify,
options: {
plugins: [
[ 'gifsicle', { interlaced: true } ],
[ 'jpegtran', { progressive: true } ],
[ 'optipng', { optimizationLevel: 5 } ],
[ 'svgo', svgoConfig ],
],
},
},
} );

},

/**
* Instantiate a SimpleBuildReportPlugin to render build output in a human-
* oriented fashion.
Expand Down
1 change: 1 addition & 0 deletions src/presets.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ const production = ( config = {} ) => {
minimizer: [
plugins.terser(),
plugins.cssMinimizer(),
plugins.imageMinimizer(),
],
emitOnErrors: false,
},
Expand Down