-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(imagemin): use image min as loader
RSPack does not support imagemin plugin
- Loading branch information
Showing
2 changed files
with
57 additions
and
40 deletions.
There are no files selected for viewing
93 changes: 55 additions & 38 deletions
93
packages/arui-scripts/src/configs/config-extras/minimizers/imagemin/imagemin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,63 @@ | ||
import ImageMinimizerPlugin from 'image-minimizer-webpack-plugin'; | ||
|
||
import configs from '../../../app-configs'; | ||
import { configs } from '../../../app-configs'; | ||
|
||
export const getImageMin = () => { | ||
export function getImageMinLoader() { | ||
const { svg, gif, jpg, png } = configs.imageMinimizer ?? {}; | ||
const doesAnyMinificationEnabled = svg?.enabled || gif?.enabled || jpg?.enabled || png?.enabled; | ||
|
||
return [ | ||
doesAnyMinificationEnabled && | ||
new ImageMinimizerPlugin({ | ||
minimizer: { | ||
implementation: ImageMinimizerPlugin.imageminMinify, | ||
options: { | ||
plugins: [ | ||
jpg?.enabled && [ | ||
'mozjpeg', | ||
{ | ||
quality: jpg?.quality, | ||
progressive: true, | ||
}, | ||
], | ||
png?.enabled && [ | ||
'optipng', | ||
{ | ||
optimizationLevel: png?.optimizationLevel, | ||
bitDepthReduction: png?.bitDepthReduction, | ||
colorTypeReduction: png?.colorTypeReduction, | ||
paletteReduction: png?.paletteReduction, | ||
interlaced: png?.interlaced, | ||
}, | ||
], | ||
svg?.enabled && ['svgo'], | ||
gif?.enabled && [ | ||
'gifsicle', | ||
{ | ||
optimizationLevel: gif?.optimizationLevel, | ||
interlaced: true, | ||
}, | ||
], | ||
].filter(Boolean), | ||
if (!doesAnyMinificationEnabled) { | ||
return false; | ||
} | ||
|
||
const loaderExtensions = [ | ||
svg?.enabled && 'svg', | ||
gif?.enabled && 'gif', | ||
jpg?.enabled && 'jpe?g', | ||
png?.enabled && 'png', | ||
].filter(Boolean); | ||
|
||
return { | ||
test: new RegExp(`\\.(${loaderExtensions.join('|')})$`), | ||
type: 'assets', | ||
use: [ | ||
{ | ||
loader: ImageMinimizerPlugin.loader, | ||
options: { | ||
minimizer: { | ||
implementation: ImageMinimizerPlugin.imageminMinify, | ||
options: { | ||
plugins: [ | ||
jpg?.enabled && [ | ||
'mozjpeg', | ||
{ | ||
quality: jpg?.quality, | ||
progressive: true, | ||
}, | ||
], | ||
png?.enabled && [ | ||
'optipng', | ||
{ | ||
optimizationLevel: png?.optimizationLevel, | ||
bitDepthReduction: png?.bitDepthReduction, | ||
colorTypeReduction: png?.colorTypeReduction, | ||
paletteReduction: png?.paletteReduction, | ||
interlaced: png?.interlaced, | ||
}, | ||
], | ||
svg?.enabled && ['svgo'], | ||
gif?.enabled && [ | ||
'gifsicle', | ||
{ | ||
optimizationLevel: gif?.optimizationLevel, | ||
interlaced: true, | ||
}, | ||
], | ||
].filter(Boolean), | ||
}, | ||
}, | ||
}, | ||
}), | ||
]; | ||
}; | ||
}, | ||
], | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters