Created
March 11, 2021 17:19
-
-
Save mkpoli/8ae86a7a16191bde608cc27ebb33f2ee to your computer and use it in GitHub Desktop.
Replace <i> tag for <svg> with icon name replaced for @mdi/js path string in Webpack
This file contains hidden or 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
| const path = require('path') | |
| const HtmlWebpackPlugin = require('html-webpack-plugin') | |
| const HtmlReplaceWebpackPlugin = require('html-replace-webpack-plugin'); | |
| module.exports = { | |
| entry: './src/index.js', | |
| plugins: [ | |
| new HtmlWebpackPlugin({ | |
| title: "Webpack", | |
| }), | |
| new HtmlReplaceWebpackPlugin([ | |
| { | |
| pattern: /<i>(.+?)<\/i>/g, | |
| replacement: function(match, icon) { | |
| const mdiJS = require('@mdi/js') | |
| const _ = require('lodash'); | |
| return `<svg style="width:24px;height:24px" viewBox="0 0 24 24"><path fill="currentColor" d="${mdiJS[_.camelCase(icon)]}"></path></svg>` | |
| } | |
| } | |
| ]) | |
| ], | |
| output: { | |
| filename: 'bundle.js', | |
| path: path.resolve(__dirname, 'dist'), | |
| clean: true, | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment