简体   繁体   English

使用Webpack在项目中添加超棒的字体

[英]Adding font-awesome to project with webpack

I've bootstrap template and I'm trying to put this to FountainJS . 我有bootstrap模板,我正试图将其放到FountainJS中 I included all scss files from template and it's ok. 我包括了模板中的所有scss文件,没关系。 Now i need to include eg font-awesome, so i used npm install font-awesome --save and add to index.js require('font-awesome'); 现在我需要包含例如font-awesome,因此我使用npm install font-awesome --save并添加到index.js require('font-awesome'); but it's still not available in project 但是它在项目中仍然不可用

My src/index.js file: 我的src/index.js文件:

var angular = require('angular');

var techsModule = require('./app/techs/index');
require('angular-ui-router');
var routesConfig = require('./routes');

var main = require('./app/main');
var header = require('./app/header');
var footer = require('./app/footer');

require('./index.scss');
require('font-awesome');

angular
  .module('app', [techsModule, 'ui.router'])
  .config(routesConfig)
  .component('app', main)
  .component('fountainHeader', header)
  .component('fountainFooter', footer);

I believe that CommonJs does not know how to load font-awesome . 我相信CommonJs不知道如何加载font-awesome If you take a look at the Font Awesome package.json it does not have main property which is used to find a file to load. 如果您查看Font Awesome package.json,它没有main属性,该属性用于查找要加载的文件。 Instead there is a property style . 而是有一种属性style If you look at the official package.json explanation you would not be able to find style property anywhere. 如果查看官方的package.json解释,您将无法在任何地方找到style属性。 You can find similar questions in StackOverflow about style property 您可以在StackOverflow中找到有关样式属性的类似问题

I believe your best bet is to require a specific file from the node_module directory. 我相信您最好的选择是从node_module目录中请求一个特定的文件。 Taking an assumption that src/ folder located in your root app folder 假设src/文件夹位于您的根应用程序文件夹中

require('../node_modules/font-awesome/css/font-awesome.css');
// or
require('../node_modules/font-awesome/css/font-awesome.min.css');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM