Webpack: replace file-loader with asset/resource asset module

merge-requests/738/head
Alex Gleason 3 years ago
parent 275d898a63
commit 50caa0d1d8
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7

@ -1,20 +1,4 @@
// Does some trickery to import all the icons into the project
// See: https://stackoverflow.com/questions/42118296/dynamically-import-images-from-a-directory-using-webpack
const icons = {};
function importAll(r) {
const pathRegex = /\.\/(.*)\.svg/i;
r.keys().forEach((key) => {
const ticker = pathRegex.exec(key)[1];
return icons[ticker] = r(key).default;
});
}
importAll(require.context('cryptocurrency-icons/svg/color/', true, /\.svg$/));
export default icons;
// For getting the icon
export const getCoinIcon = ticker => icons[ticker] || icons.generic || null;
export const getCoinIcon = ticker => {
return require(`cryptocurrency-icons/svg/color/${ticker.toLowerCase()}.svg`);
};

@ -1,20 +1,9 @@
const { join } = require('path');
const { settings } = require('../configuration');
module.exports = {
test: new RegExp(`(${settings.static_assets_extensions.join('|')})$`, 'i'),
use: [
{
loader: 'file-loader',
options: {
name(file) {
if (file.includes(settings.source_path)) {
return 'packs/media/[path][name]-[contenthash].[ext]';
}
return 'packs/media/[folder]/[name]-[contenthash:8].[ext]';
},
context: join(settings.source_path),
},
},
],
type: 'asset/resource',
generator: {
filename: 'packs/media/[contenthash][ext]',
},
};

Loading…
Cancel
Save