Does anyone knows the way of adding font-awsome to new Ionic 4 project (currently I'm using 4.0.0-beta.15).
Adding it to v3 is nicely explained here:
https://charlouze.github.io/ionic/2017/05/31/Ionic-3-and-Font-Awesome.html
and it works great for Ionic V3, but unfortunatelly not V4.
install font-awesome
npm install font-awesome --save --save-exact
copy.config.js
copyFonts: {
src: [
'{{ROOT}}/node_modules/ionicons/dist/fonts/**/*',
'{{ROOT}}/node_modules/ionic-angular/fonts/**/*',
'{{ROOT}}/node_modules/font-awesome/fonts/**/*'],
dest: '{{WWW}}/assets/fonts'
},
sass.config.js
includePaths: [
'node_modules/ionic-angular/themes',
'node_modules/ionicons/dist/scss',
'node_modules/ionic-angular/fonts',
'node_modules/font-awesome/scss'
],
variable.scss
$fa-font-path: $font-path;
#import "font-awesome";
home.html
<i class="fa fa-users"></i>
Please follow the above steps. That is working for me.
Related
My ultimate goal is to get e2e and unit code coverage for my Vue 3 app using Cypress in my CI/CD pipelines.
However, when using the following configuration in my babel.config.js I get a flood of repeated error messages that read don't know how to turn this value into a node at transformFile.next (<anonymous>) for each Vue file in my app that uses <script setup>.
babel.config.js
module.exports = {
presets: [
'#vue/cli-plugin-babel/preset',
],
plugins: [
['babel-plugin-istanbul', {
extension: ['.js', '.vue']
}]
],
};
package.json
"dependencies": {
"core-js": "^3.6.5",
"vue": "^3.0.0"
},
"devDependencies": {
"#vue/cli-plugin-babel": "~4.5.15",
"#vue/cli-plugin-eslint": "~4.5.15",
"#vue/cli-service": "~4.5.15",
"#vue/compiler-sfc": "^3.0.0",
"babel-eslint": "^10.1.0",
"babel-plugin-istanbul": "^6.1.1",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^7.0.0"
},
App.vue
<script setup>
import HelloWorld from './components/HelloWorld.vue'
</script>
My concern is that the plugin doesn't know how to handle Vue 3's script setup syntax.
Sadly, the only how-to guides I can find online are for Vue 2 or React apps.
https://docs.cypress.io/guides/tooling/code-coverage#Using-NYC
https://vuejsdevelopers.com/2020/07/20/code-coverage-vue-cypress/
So my question is: what can I do to get my app to transpile while using babel-plugin-istanbul and script setup?
Steps to Reproduce:
Create a new Vue 3 app with vue-cli-service
Install babel-plugin-istanbul in your dev dependencies
Configure your babel.config.js as shown above
Convert your App.vue to use <script setup>
Run npm run serve
Expected behavior:
The app transpiles with no errors
Actual behavior:
Transpilation failure with don't know how to turn this value into a node errors for App.vue.
The resolve is to use istanbul in the babel config (as given in Cypress docs).
The cause isn't apparent, without <script setup> the full name babel-plugin-istanbul works ok.
plugins: [
['istanbul', {
extension: ['.js', '.vue']
}]
],
I am solving same problem and I can point out two things:
The problem is in babel.config.js file especially with .vue extension, when you remove it works, but for me it instrument all files.
I have a feeling another problem is with CLI versions plugins. I don't have problem to run the cypress code coverage plugin with older packages.
If add extension:['.vue'] in bable.config.js configuration, getting below error.
src/pages/somefile.vue?vue&type=script&setup=true&lang=js
Module build failed (from ./node_modules/#vue/cli-plugin-babel/node_modules/babel-loader/lib/index.js):
Error: src/pages/somefile.vue: don't know how to turn this value into a node
I ran into this as well. It turned out to be a bug in the istanbul-lib-instrument package, which was fixed in this PR: https://github.com/istanbuljs/istanbuljs/pull/662
If you upgrade your installed copy of istanbul-lib-instrument to 5.2.1 (i.e., npm update istanbul-lib-instrument) the issue should go away.
I have a h1 tag and I'm trying to get the node using specific heading level but running to the error:
Found multiple elements with the role "heading"
According the documentation this query supposed to return only h1.
here is the example:
import React from "react";
import { render, screen } from "#testing-library/react";
it("Should found only header1", async () => {
render(
<div>
<h1>editable content</h1>
<p>and</p>
<h2>other header</h2>
</div>
);
screen.debug(screen.getByRole("heading", { level: 1 }));
});
and here is the error:
Found multiple elements with the role "heading"
(If this is intentional, then use the `*AllBy*` variant of the query (like `queryAllByText`, `getAllByText`, or `findAllByText`)).
<body>
<div>
<div>
<h1>
editable content
</h1>
<p>
and
</p>
<h2>
other header
</h2>
</div>
</div>
</body>
Solved.
The reason is the version of the library. By default create-react-app installing outdated version of #testing-library.
Run CLI command npm outdated and check the versions of dependencies:
Package Current Wanted Latest
#testing-library/jest-dom 4.2.4 4.2.4 5.11.4
#testing-library/react 9.5.0 9.5.0 11.0.2
#testing-library/user-event 7.2.1 7.2.1 12.1.4
To update dependencies open package.json and manually update them to the latest:
...
"dependencies": {
...
"#testing-library/jest-dom": "^5.11.4",
"#testing-library/react": "^11.0.2",
"#testing-library/user-event": "^12.1.4"
...
},
...
Save changes and run CLI command: npm install
There are a lot of tutorials and articles of how to include Font Awesome in an Ionic 3 project but I struggled finding any on how to add Font Awesome into an Ionic 4 project. So this poses the question, how do you add and use Font Awesome in an Ionic 4 project?
I have tried using the following tutorial without much success. I tried following the steps outlined in the following StackOverflow answer which did not work either.
To get Font Awesome working in an Ionic 4 project you can follow the steps below.
Firstly, you need to install all the npm packages, the first two are required but you can decide whether you need the solid, regular or brands icons, I will be using all of them. Go ahead and execute the following npm commands in your terminal:
npm i --save #fortawesome/fontawesome-svg-core
npm i --save #fortawesome/angular-fontawesome
npm i --save #fortawesome/free-solid-svg-icons
npm i --save #fortawesome/free-regular-svg-icons
npm i --save #fortawesome/free-brands-svg-icons
Once you have done that, navigate to your app.module.ts in your project and add the following:
import { FontAwesomeModule } from '#fortawesome/angular-fontawesome';
import { library } from '#fortawesome/fontawesome-svg-core';
Depending on which font packages you installed, add the following:
import { fas } from '#fortawesome/free-solid-svg-icons';
import { far } from '#fortawesome/free-regular-svg-icons';
import { fab } from '#fortawesome/free-brands-svg-icons';
Once they have been imported at the top of your file you will need to include the FontAwesomeModule in your imports:
.....
imports: [...., FontAwesomeModule],
.....
Once again, depending on what icons you chose you will need to add them to the Font Awesome library that was imported earlier. Add this underneath your last import (above #NgModule()):
library.add(fas, far, fab);
Then navigate to the module of the page that you would like to use the fonts in i.e. home.module.ts and then import and add the FontAwesomeModule:
import { FontAwesomeModule } from '#fortawesome/angular-fontawesome'
....
#NgModule({
imports: [
...
FontAwesomeModule
...
],
})
Then finally you can use the icon in that page's HTML by inserting the following where you'd like the icon:
<fa-icon [icon]="['fas', 'graduation-cap']" slot="end"></fa-icon>
You can replace, fas with the correct library i.e. far, fas & fab and then the name of the icon, which in this case was graduation-cap.
Run the following command:
npm install --save-dev #fortawesome/fontawesome-free
Then, in angular.json append this on "styles":
{
"input": "node_modules/#fortawesome/fontawesome-free/css/all.css"
}
Just in case if someone deals with FontAwesome PRO. I've recently bought FontAwesome pro icons and integreted them like this:
copy the FontAwesome webfonts folder in src/assets/
copy the FontAwesome scss folder in src/theme/
change the $fa-font-path in _variables.scss with assets/webfonts !default;
add in global.scss
#import './theme/[YourDirectoryfontawesomeScss]/fontawesome.scss';
#import './theme/[YourDirectoryfontawesomeScss]/solid.scss';
#import './theme/[YourDirectoryfontawesomeScss]/brands.scss';
#import './theme/[YourDirectoryfontawesomeScss]/light.scss';
#import './theme/[YourDirectoryfontawesomeScss]/regular.scss';
Finally you can use them with the i tag. For example
<i class="fas fa-stack-overflow"></i>
you can find more details about the fa- classes here
https://fontawesome.com/how-to-use/on-the-web/setup/getting-started
I was racking my brain trying to get this working with Ionic 5/Angular 10 and couldn't get it working. I figured it in the end, should anyone else require it.
For Ionic 5/Angular 10
Run ng add #fortawesome/angular-fontawesome#latest in your project folder and select the icons you require.
In app.module.ts add the following:
import { FaIconLibrary, FontAwesomeModule } from '#fortawesome/angular-fontawesome';
import { fas } from '#fortawesome/free-solid-svg-icons'; //Solid icons
import { far } from '#fortawesome/free-regular-svg-icons'; // Regular icons
import { fab } from '#fortawesome/free-brands-svg-icons'; // Brand icons
And import FontAwesomeModule to the imports declarables so it looks like this:
#NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule, FontAwesomeModule],
providers: [
StatusBar,
SplashScreen,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
],
bootstrap: [AppComponent],
})
And then export a library constructor as so...
export class AppModule {
constructor(library: FaIconLibrary) {
library.addIconPacks(fas, far, fab);
}
}
Go to the module you wish to use Font Awesome (e.g. mypage.module.ts) and import the FontAwesomeModule.
Finally in your HTML, e.g. mypage.page.html simply use <fa-icon icon="home"></fa-icon> to display an icon.
If you run in to any issues, make sure you stop Ionic first and run ionic serve again as this should recompile the framework.
Also take a look at https://github.com/FortAwesome/angular-fontawesome/blob/master/docs/usage/features.md for a full list of the features available in its usage.
The easiest way for the Angular user is to write ng add #fortawesome/angular-fontawesome#latest
I am not able to install bootstrap 4(beta) to my MVC project. To be precise popper.js nuget dependency is failing to install. Please let me know any possible way to do it(bower install is still a way but I want to go with nuget)
Could not install package 'popper.js 1.11.0'. You are trying to
install this package into a project that targets
'.NETFramework,Version=v4.6.2', but the package does not contain any
assembly references or content files that are compatible with that
framework. For more information, contact the package author
I was finally able to get Bootstrap 4-Beta working by doing the following:
1.) Install the popper.js NuGet Package V1.12.3
2.) Install Bootstrap4-beta NuGet Package
3.) Update your BundleConfig.cs to include the following: Note the popper.js path
bundles.Add(new ScriptBundle("~/Scrpts/Bootstrap").Include(
/*** Make sure popper.js is pointing to umd ***/
"~/Scripts/umd/popper.js",
"~/Scripts/bootstrap.js",
));
bundles.Add(new StyleBundle("~/CSS/Bootstrap").Include(
"~/Content/bootstrap.css"));
For some reason if you try to use the popper.js in the root of the \Scripts folder you will receive the error:
SyntaxError: export declarations may only appear at top level of a module
but the version in the /Scripts/umd seems to work.
You can get around this by manually adding the popper.js package to your packages config.
<package id="popper.js" version="1.11.1" targetFramework="net462" />
Then you can go into the nuget package manager and install normally.
I managed to get around this problem by downloading the latest (1.12.3 at the time of writing) popper.js nuget package before updating to bootstrap 4.0.
Then in the bundles.config I added the popper js like this
bundles.Add(new ScriptBundle("~/bundles/popper").Include(
"~/Scripts/umd/popper.js"));
The umd version is the only one that worked for me the others gave an console error of
Unrecognised Token Export
Just make sure to include the popper js file before the bootstrap one.
#Scripts.Render("~/bundles/popper")
#Scripts.Render("~/bundles/bootstrap")
I also noticed that this then broke the majority of the auto produced template as it's based on previous versions of bootstrap. The navbar almost completely vanishes. I managed to fix mine by replacing it with the following, but this doesn't include any items in the mobile menu.
<div class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">My Blog</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse">
<ul class="navbar-nav">
<li class="nav-item">#Html.ActionLink("Home", "Index", "Home", new { #class = "nav-link" })</li>
<li class="nav-item">#Html.ActionLink("About", "About", "Home", new { #class = "nav-link" })</li>
<li class="nav-item">#Html.ActionLink("Contact", "Contact", "Home", new { #class = "nav-link" })</li>
</ul>
</div>
</div>
I know this question has a few good answers but this was the full solution that worked for me so I thought I'd share it in the hope that it spares someone a bit of time in the future.
Same problem here... I created an issue on GitHub for this: https://github.com/FezVrasta/popper.js/issues/387
The Popper.js NuGet package has been broken until version 1.12.2.
Bootstrap is still requiring the version 1.11.x, which is, unfortunately, broken.
You should wait for Bootstrap to close this issue:
https://github.com/twbs/bootstrap/issues/23622
meanwhile you can follow the suggestion of Rob Quincey.
Before installing the package using NuGet, expand "Options" and change the "Dependency Behavior" to "Highest". Now when you install the package the latest popper.js will get installed first allowing bootstrap to get installed as well.
This prevented me from having to install popper separately.
Again, not a fix, but similar to the fix by #Alex.
I resolved it by installing them separately using NuGet, so first installing popperjs (just search for popper in the NuGet package manager) then installing Bootstrap 4. It seems to only hit the above error when it needs to download it as a dependency rather than standalone. Very odd.
I was not happy with all the files and folders and typescript-related code and NuGet and debugger messages that came with Popper, so I am using CDNs, like so:
#Scripts.Render("~/bundles/jquery")
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>
So far it's all worked fine.
For uses of ASP.NET Webforms:
I've created a new Project with preinstalled Packages (Bootstrap, Popper, jQuery), updated them to the newest version and did:
add to App_Start/BundleConfig.cs
bundles.Add(new ScriptBundle("~/bundles/popper").Include(
"~/Scripts/umd/popper.js"));
Add to Header (Master Page)
<asp:PlaceHolder runat="server">
<%: Scripts.Render("~/bundles/popper") %>
<%: Scripts.Render("~/bundles/bootstrap")%>
</asp:PlaceHolder>
I am not sure the title is correct but i am new with Bower, Gulp, Strongloop and even AngularJS.
I am updating an existing app, using bower, gulp and Strongloop, and i would like to add a bower componenent to the app (this one : https://github.com/fraywing/textAngular).
i did bower install textAngular as explained in the readme file, but now i should add those lines to my app :
<link rel='stylesheet' href='/bower_components/textAngular/dist/textAngular.css'>
<script src='/bower_components/textAngular/dist/textAngular-rangy.min.js'></script>
<script src='/bower_components/textAngular/dist/textAngular-sanitize.min.js'></script>
<script src='/bower_components/textAngular/dist/textAngular.min.js'></script>
But my app is using Strongloop, gulp and coffee script, so there is lot of file, not looking like classic html file and i am totally lost.
Can you help me find the next step to make this works ?
Thanks alot :)
I finally found my mistake, i need to add --saved at the end of bower command line.
So real line is : bower install textAngular --saved
Plus i should add textAngular in my angular module definition :
angular.module "starter", [
...
"textAngular"
...
]
Note that you should install too font-awesome and rangy to make it works completly