Menggunakan webpack dan scss:
Instal font-awesome menggunakan npm (menggunakan instruksi pengaturan di https://fontawesome.com/how-to-use )
npm install @fortawesome/fontawesome-free
Berikutnya, menggunakan copy-Webpack-plugin , menyalin webfonts folder dari node_modules ke Anda dist folder selama Webpack proses membangun. ( https://github.com/webpack-contrib/copy-webpack-plugin )
npm install copy-webpack-plugin
Di webpack.config.js , konfigurasikan copy-webpack-plugin . CATATAN: Folder default webpack 4 dist adalah "dist", jadi kami menyalin folder webfonts dari node_modules ke folder dist.
const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = {
plugins: [
new CopyWebpackPlugin([
{ from: './node_modules/@fortawesome/fontawesome-free/webfonts', to: './webfonts'}
])
]
}
Terakhir, di file main.scss Anda , beri tahu fontawesome di mana folder webfonts telah disalin dan impor file SCSS yang Anda inginkan dari node_modules .
$fa-font-path: "/webfonts"; // destination folder in dist
//Adapt the path to be relative to your main.scss file
@import "../node_modules/@fortawesome/fontawesome-free/scss/fontawesome";
//Include at least one of the below, depending on what icons you want.
//Adapt the path to be relative to your main.scss file
@import "../node_modules/@fortawesome/fontawesome-free/scss/brands";
@import "../node_modules/@fortawesome/fontawesome-free/scss/regular";
@import "../node_modules/@fortawesome/fontawesome-free/scss/solid";
@import "../node_modules/@fortawesome/fontawesome-free/scss/v4-shims"; // if you also want to use `fa v4` like: `fa fa-address-book-o`
dan terapkan yang berikut ini font-family
ke wilayah yang diinginkan dalam dokumen html Anda di mana Anda ingin menggunakan ikon fontawesome.
Contoh :
body {
font-family: 'Font Awesome 5 Free'; // if you use fa v5 (regular/solid)
// font-family: 'Font Awesome 5 Brands'; // if you use fa v5 (brands)
}