add svgr loader for icons (#21248)
* add svgr loader for icons Signed-off-by: Kerry Archibald <kerrya@element.io> * fix config, move dep to dev Signed-off-by: Kerry Archibald <kerrya@element.io> * add svg types Signed-off-by: Kerry Archibald <kerrya@element.io> * add aria-hidden and role=img to svg Signed-off-by: Kerry Archibald <kerrya@element.io> * make svgProps explicitly overridable Signed-off-by: Kerry Archibald <kerrya@element.io> * role presentatino Signed-off-by: Kerry Archibald <kerrya@element.io> * update copyright Signed-off-by: Kerry Archibald <kerrya@element.io>
This commit is contained in:
parent
240c3be014
commit
9a17a61809
4 changed files with 188 additions and 6 deletions
|
@ -455,7 +455,52 @@ module.exports = (env, argv) => {
|
|||
},
|
||||
},
|
||||
{
|
||||
test: /\.(gif|png|svg|ttf|woff|woff2|xml|ico)$/,
|
||||
test: /\.svg$/,
|
||||
use: [
|
||||
{
|
||||
loader: '@svgr/webpack',
|
||||
options: {
|
||||
namedExport: 'Icon',
|
||||
svgProps: {
|
||||
role: 'presentation',
|
||||
'aria-hidden': true,
|
||||
},
|
||||
// props set on the svg will override defaults
|
||||
expandProps: 'end',
|
||||
svgoConfig: {
|
||||
plugins: {
|
||||
// generates a viewbox if missing
|
||||
removeDimensions: true,
|
||||
},
|
||||
},
|
||||
esModule: false,
|
||||
name: '[name].[hash:7].[ext]',
|
||||
outputPath: getAssetOutputPath,
|
||||
publicPath: function (url, resourcePath) {
|
||||
const outputPath = getAssetOutputPath(url, resourcePath);
|
||||
return toPublicPath(path.join("../..", outputPath));
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
loader: 'file-loader',
|
||||
options: {
|
||||
esModule: false,
|
||||
name: '[name].[hash:7].[ext]',
|
||||
outputPath: getAssetOutputPath,
|
||||
publicPath: function (url, resourcePath) {
|
||||
// CSS image usages end up in the `bundles/[hash]` output
|
||||
// directory, so we adjust the final path to navigate up
|
||||
// twice.
|
||||
const outputPath = getAssetOutputPath(url, resourcePath);
|
||||
return toPublicPath(path.join("../..", outputPath));
|
||||
},
|
||||
},
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
test: /\.(gif|png|ttf|woff|woff2|xml|ico)$/,
|
||||
// Use a content-based hash in the name so that we can set a long cache
|
||||
// lifetime for assets while still delivering changes quickly.
|
||||
oneOf: [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue