2017-12-07 09:44:50 -08:00
|
|
|
/**
|
|
|
|
* Replace fontawesome symbols
|
|
|
|
*/
|
|
|
|
|
|
|
|
const StringReplacePlugin = require('string-replace-webpack-plugin');
|
|
|
|
|
2017-12-07 20:10:31 -08:00
|
|
|
import * as fontawesome from '@fortawesome/fontawesome';
|
|
|
|
import * as regular from '@fortawesome/fontawesome-free-regular';
|
|
|
|
import * as solid from '@fortawesome/fontawesome-free-solid';
|
|
|
|
import * as brands from '@fortawesome/fontawesome-free-brands';
|
2017-12-07 09:44:50 -08:00
|
|
|
|
2017-12-07 20:10:31 -08:00
|
|
|
// Add icons
|
|
|
|
fontawesome.library.add(regular);
|
2017-12-07 09:44:50 -08:00
|
|
|
fontawesome.library.add(solid);
|
2017-12-07 20:10:31 -08:00
|
|
|
fontawesome.library.add(brands);
|
2017-12-07 09:44:50 -08:00
|
|
|
|
|
|
|
export default () => ({
|
|
|
|
enforce: 'pre',
|
|
|
|
test: /\.(tag|js|ts)$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
loader: StringReplacePlugin.replace({
|
|
|
|
replacements: [{
|
|
|
|
pattern: /%fa:(.+?)%/g, replacement: (_, key) => {
|
|
|
|
const args = key.split(' ');
|
|
|
|
let prefix = 'fas';
|
2017-12-07 20:10:31 -08:00
|
|
|
const classes = [];
|
2017-12-07 09:44:50 -08:00
|
|
|
let transform = '';
|
|
|
|
let name;
|
|
|
|
|
|
|
|
args.forEach(arg => {
|
2017-12-07 20:10:31 -08:00
|
|
|
if (arg == 'R' || arg == 'S' || arg == 'B') {
|
2017-12-07 09:44:50 -08:00
|
|
|
prefix =
|
|
|
|
arg == 'R' ? 'far' :
|
|
|
|
arg == 'S' ? 'fas' :
|
2017-12-07 20:10:31 -08:00
|
|
|
arg == 'B' ? 'fab' :
|
2017-12-07 09:44:50 -08:00
|
|
|
'';
|
|
|
|
} else if (arg[0] == '.') {
|
2017-12-07 20:10:31 -08:00
|
|
|
classes.push('fa-' + arg.substr(1));
|
2017-12-07 09:44:50 -08:00
|
|
|
} else if (arg[0] == '-') {
|
|
|
|
transform = arg.substr(1).split('|').join(' ');
|
|
|
|
} else {
|
|
|
|
name = arg;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-12-07 20:10:31 -08:00
|
|
|
const icon = fontawesome.icon({ prefix, iconName: name }, {
|
|
|
|
classes: classes
|
|
|
|
});
|
2017-12-07 09:44:50 -08:00
|
|
|
|
|
|
|
if (icon) {
|
|
|
|
icon.transform = fontawesome.parse.transform(transform);
|
2017-12-07 21:35:50 -08:00
|
|
|
return `<i data-fa class="${name}">${icon.html[0]}</i>`;
|
2017-12-07 09:44:50 -08:00
|
|
|
} else {
|
|
|
|
console.warn(`'${name}' not found in fa`);
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
})
|
|
|
|
});
|