From a7aa24e7a3127f9dee43b178aeac2c4c6b827e99 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 8 Dec 2017 02:44:50 +0900 Subject: wip --- webpack/module/rules/fa.ts | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 webpack/module/rules/fa.ts (limited to 'webpack/module/rules/fa.ts') diff --git a/webpack/module/rules/fa.ts b/webpack/module/rules/fa.ts new file mode 100644 index 0000000000..57691f9899 --- /dev/null +++ b/webpack/module/rules/fa.ts @@ -0,0 +1,54 @@ +/** + * Replace fontawesome symbols + */ + +const StringReplacePlugin = require('string-replace-webpack-plugin'); + +const fontawesome = require('@fortawesome/fontawesome'); +const solid = require('@fortawesome/fontawesome-free-solid'); + +// Adds all the icons from the Solid style into our library for easy lookup +fontawesome.library.add(solid); + +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'; + let klass = ''; + let transform = ''; + let name; + + args.forEach(arg => { + if (arg == 'R' || arg == 'S') { + prefix = + arg == 'R' ? 'far' : + arg == 'S' ? 'fas' : + ''; + } else if (arg[0] == '.') { + klass += arg.substr(1) + ' '; + } else if (arg[0] == '-') { + transform = arg.substr(1).split('|').join(' '); + } else { + name = arg; + } + }); + + const icon = fontawesome.icon({ prefix, iconName: name }); + + if (icon) { + icon.class = klass; + icon.transform = fontawesome.parse.transform(transform); + return `${icon.html[0]}`; + } else { + console.warn(`'${name}' not found in fa`); + return ''; + } + } + }] + }) +}); -- cgit v1.2.3-freya