I have a problem. In my Rails 7 application I am trying to use Font-Awesome icons. I have installed this npm package and then added:
import "#fortawesome/fontawesome-free"
to my app.ts. After that I checked the page where I have put this icon:
<i class="fa-solid fa-caret-down"></i>
But the icon is not showing up. Going into inspector mode, I can see that the icon has a height and width of 0:0, so something must be wrong with installation, maybe I am missing something. I already tried installing the Font-Awesome gem, instead of the NPM, but that gave me all kinds of errors with ESBuild about not be able to compile .svg files and a few other extensions. What am I missing here with the installation?
UPDATE
After installing the gem font-awesome-sass and running bundle install, I added the import statement like this in my app.scss:
#import "bootstrap/scss/bootstrap";
#import "font-awesome";
Unfortunately this results in the following error output:
✘ [ERROR] [plugin sass-plugin] Can't find stylesheet to import.
╷
9 │ #import "font-awesome";
│ ^^^^^^^^^^^^^^
╵
- 9:9 root stylesheet
/app/node_modules/esbuild/lib/main.js:1596
let error = new Error(`${text}${summary}`);
^
Error: Build failed with 1 error:
error: Can't find stylesheet to import.
╷
9 │ #import "font-awesome";
│ ^^^^^^^^^^^^^^
╵
- 9:9 root stylesheet
at failureErrorWithLog (/app/node_modules/esbuild/lib/main.js:1596:15)
at /app/node_modules/esbuild/lib/main.js:1052:28
at runOnEndCallbacks (/app/node_modules/esbuild/lib/main.js:1468:61)
at buildResponseToResult (/app/node_modules/esbuild/lib/main.js:1050:7)
at /app/node_modules/esbuild/lib/main.js:1162:14
at responseCallbacks.<computed> (/app/node_modules/esbuild/lib/main.js:697:9)
at handleIncomingPacket (/app/node_modules/esbuild/lib/main.js:752:9)
at Socket.readFromStdout (/app/node_modules/esbuild/lib/main.js:673:7)
at Socket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:324:12) {
errors: [
{
detail: undefined,
id: '',
location: null,
notes: [],
pluginName: 'sass-plugin',
text: "Can't find stylesheet to import.\n" +
'\x1B[34m ╷\x1B[0m\n' +
'\x1B[34m9 │\x1B[0m #import \x1B[31m"font-awesome"\x1B[0m;\n' +
'\x1B[34m │\x1B[0m \x1B[31m ^^^^^^^^^^^^^^\x1B[0m\n' +
'\x1B[34m ╵\x1B[0m\n' +
' - 9:9 root stylesheet'
}
],
warnings: []
}
I see! How strange :)
This is how I have it:
gem "font-awesome-sass", "~> 6.1"
bundle install
#import "bootstrap/scss/bootstrap";
#import "font-awesome";
and icons (FontAwesome 5.15.4 and Free icons that have fas fa-something) work perfectly this way:
<i class="fas fa-search"></i>
but they don't work if I want to use unicode icons as content in ::before and and ::after pseudo selectors. After testing on font awesome's own code on codepen and seeing that unicode icons didn't work if the stack was font awesome free, I gave up and am using bootstrap icons for these purposes.
Related
It has been some time now that I cannot figure out this error, I am receiving when pushing it to the Heroku.
ERROR in ./app/javascript/stylesheets/application.scss
remote: Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
remote: ModuleBuildError: Module build failed (from ./node_modules/postcss-loader/src/index.js):
remote: ParserError: Syntax Error at line: 1, column 25
Full error message: https://gist.github.com/zilton7/bbac886c75523aab75bc3561ec22ed55
I have tried many variations for application.scss, but once I have bootstrap uncommented I get the said issue.
application.scss
// #import "~bootswatch/dist/darkly/variables";
#import "~bootstrap/scss/bootstrap";
// #import "~bootswatch/dist/darkly/bootswatch";
// #import "trix/dist/trix";
// #import "custom"
I had same issue while deploying my rails application on Heroku. I resolve this by changing bootstrap version in package.json file
from :
To:
Source : https://github.com/rails/webpacker/issues/3188
How can i import bootstrap.css,jquery and JavaScript in my angular components and how can convert html webpage to angular webpage
Style.css
// Globally declaration for styles
#import url("./assets/css/bootstrap.css");
You can install bootstrap using npm.
npm install bootstrap --save
and then set the path in angular.json file as
"styles": [
"src/styles.css",
"node_modules/bootstrap/dist/css/bootstrap.min.css",
]
This will do the work.
I'm having a hard time getting the css (scss to be more specific) for Vaadin spreadsheet to be included in my project's theme.
Do I add it like this to styles.scss?
#import "../valo/valo.scss";
.wastecentertheme {
#include valo;
}
#mixin addons {
#include spreadsheet;
}
Or is it like this?
#import "../valo/valo.scss";
.wastecentertheme {
#include valo;
#mixin addons {
#include spreadsheet;
}
}
The former compiles but the output .css does not appear to have any of the required rules. The second breaks with this message...
[INFO] --- vaadin-maven-plugin:8.1.1:compile-theme (default) # portal ---
[INFO] Updating theme VAADIN/themes/base
[INFO] Theme "VAADIN/themes/base" compiled
[INFO] Updating theme VAADIN/themes/valo
[INFO] Theme "VAADIN/themes/valo" compiled
[INFO] Updating theme VAADIN/themes/wastecentertheme
[ERROR] Aug 09, 2017 1:36:31 AM com.vaadin.sass.internal.handler.SCSSErrorHandler log
[ERROR] SEVERE: Error when parsing file
[ERROR] /usr/local/code/Waste Center/src/main/webapp/VAADIN/themes/wastecentertheme/styles.scss on line 4, column 17
[ERROR] Aug 09, 2017 1:36:31 AM com.vaadin.sass.internal.handler.SCSSErrorHandler log
[ERROR] SEVERE: encountered "#mixin". Was expecting one of: "}" "+" "-" ";" ">" "~" "[" "*" "%" "&" "." "and" "or" "not" ":" "#{" "through" "in" "#include" "#debug" "#warn" "#for" "#each" "#while" "#if" "#extend" "#content" <MICROSOFT_RULE> <IDENT> <VARIABLE> <HASH> "#import" "#media" <KEY_FRAME_SYM> <ATKEYWORD>
[ERROR] org.w3c.css.sac.CSSParseException: encountered "#mixin". Was expecting one of: "}" "+" "-" ";" ">" "~" "[" "*" "%" "&" "." "and" "or" "not" ":" "#{" "through" "in" "#include" "#debug" "#warn" "#for" "#each" "#while" "#if" "#extend" "#content" <MICROSOFT_RULE> <IDENT> <VARIABLE> <HASH> "#import" "#media" <KEY_FRAME_SYM> <ATKEYWORD>
[ERROR] at com.vaadin.sass.internal.parser.Parser.reportError(Parser.java:418)
[ERROR] at com.vaadin.sass.internal.parser.Parser.styleRule(Parser.java:2203)
[ERROR] at com.vaadin.sass.internal.parser.Parser.topLevelDeclaration(Parser.java:591)
[ERROR] at com.vaadin.sass.internal.parser.Parser.parserUnit(Parser.java:487)
[ERROR] at com.vaadin.sass.internal.parser.Parser.parseStyleSheet(Parser.java:122)
[ERROR] at com.vaadin.sass.internal.ScssStylesheet.get(ScssStylesheet.java:172)
[ERROR] at com.vaadin.sass.SassCompiler.main(SassCompiler.java:92)
[ERROR]
[ERROR] Aug 09, 2017 1:36:31 AM com.vaadin.sass.internal.handler.SCSSErrorHandler warn
[ERROR] WARNING: Warning when parsing file
[ERROR] /usr/local/code/Waste Center/src/main/webapp/VAADIN/themes/wastecentertheme/styles.scss on line 8, column 4
[ERROR] Aug 09, 2017 1:36:31 AM com.vaadin.sass.internal.handler.SCSSErrorHandler warn
[ERROR] WARNING: Skipping: }
[ERROR] org.w3c.css.sac.CSSParseException: Skipping: }
[ERROR] at com.vaadin.sass.internal.parser.Parser.reportWarningSkipText(Parser.java:434)
[ERROR] at com.vaadin.sass.internal.parser.Parser.topLevelDeclaration(Parser.java:618)
[ERROR] at com.vaadin.sass.internal.parser.Parser.parserUnit(Parser.java:487)
[ERROR] at com.vaadin.sass.internal.parser.Parser.parseStyleSheet(Parser.java:122)
[ERROR] at com.vaadin.sass.internal.ScssStylesheet.get(ScssStylesheet.java:172)
[ERROR] at com.vaadin.sass.SassCompiler.main(SassCompiler.java:92)
[ERROR]
[ERROR] Compiling theme "VAADIN/themes/wastecentertheme" failed
Any ideas? Maybe I need to grab the .scss from the .jar maven imports for Vaadin-Spreadsheet and drop a copy of it in my directory and do an #import as well?
addons.scss is a file which is managed by Vaadin through Maven targets. If some add-on has css that need to be included in the theme, then the maven target will automatically include it in addons.scss upon theme compilation. It is split into an own file so that it can be overwritten at any point of time and it should not be manually edited. After adding the Spreadsheet dependency to your pom.xml and running for example mvn install, addons.scss should look like this:
/* This file is automatically managed and will be overwritten from time to time. */
/* Do not manually edit this file. */
/* Provided by vaadin-spreadsheet-2.0.1.jar */
#import "../../../VAADIN/addons/spreadsheet/spreadsheet.scss";
/* Import and include this mixin into your project theme to include the addon themes */
#mixin addons {
#include spreadsheet;
}
then the default setup of styles.scss includes the addons mixin to the main theme. styles.scss:
#import "addons.scss";
#import "apptheme.scss";
#import "designs.scss";
/* This file prefixes all rules with the theme name to avoid causing conflicts with other themes. */
/* The actual styles should be defined in apptheme.scss */
.apptheme {
#include vaadin-crud-template;
#include addons;
#include apptheme;
}
Not that Designer template styling is handled the same way with designs.scss. The developer's custom scss goes into the apptheme.scss.
The answer seems to be that Vaadin somehow auto generated an addons file you should include as an important as well as include directive in .scss. This should really be documented more clearly.
#import "../valo/valo.scss";
#import "addons.scss";
.wastecentertheme {
#include valo;
#include addons;
}
Problem and question
I've always had problems with CSS code, so now I always use SaSS code. But my question is: how can I use SaSS for an ASP.NET MVC application?
I've tried
I've tried tried to use a Gulp task for this. I've used these commands
npm init
npm install --save gulp
npm install --save gulp-sass
Here is my package.json file:
{
"name": "markeonline",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Hein Pauwelyn",
"license": "ISC",
"dependencies": {
"gulp": "^3.9.1",
"gulp-sass": "^3.1.0"
}
}
Here is the gulpfile.js
var gulp = require("gulp"),
sass = require("gulp-sass");
// other content removed
gulp.task("sass", function () {
return gulp.src('./**/*.scss')
.pipe(sass())
.pipe(gulp.dest(project.webroot + './MarkeOnline.Website/Content/css'));
});
Here is my project structure:
This code gives me the following error if I use the command below:
gulp sass
ReferenceError: project is not defined
[17:50:58] ReferenceError: project is not defined
at Gulp.<anonymous> (D:\Documenten\Howest\Semester 4\05 - Project\MarkeOnlinebis\Project Execution\MarkeOnline\gulpfile.js:9:23)
at module.exports (D:\Documenten\Howest\Semester 4\05 - Project\MarkeOnlinebis\Project Execution\MarkeOnline\node_modules\orchestrator\lib\runTask.js:34:7)
at Gulp.Orchestrator._runTask (D:\Documenten\Howest\Semester 4\05 - Project\MarkeOnlinebis\Project Execution\MarkeOnline\node_modules\orchestrator\index.js:273:3)
at Gulp.Orchestrator._runStep (D:\Documenten\Howest\Semester 4\05 - Project\MarkeOnlinebis\Project Execution\MarkeOnline\node_modules\orchestrator\index.js:214:10)
at Gulp.Orchestrator.start (D:\Documenten\Howest\Semester 4\05 - Project\MarkeOnlinebis\Project Execution\MarkeOnline\node_modules\orchestrator\index.js:134:8)
at C:\Users\hein_\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:129:20
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
at Module.runMain (module.js:592:11)
at run (bootstrap_node.js:394:7)
events.js:160
throw er; // Unhandled 'error' event
^
Error: node_modules\node-sass\test\fixtures\depth-first\_vars.scss
Error: Undefined variable: "$import-counter".
on line 1 of node_modules/node-sass/test/fixtures/depth-first/_vars.scss
>> $import_counter: $import_counter + 1;
-----------------^
at options.error (D:\Documenten\Howest\Semester 4\05 - Project\MarkeOnlinebis\Project Execution\MarkeOnline\node_modules\node-sass\lib\index.js:291:26)
Try Web Compiler plugin instead this is what I use to compile SCSS in MVC.
A Visual Studio extension that compiles LESS, Sass, JSX, ES6 and CoffeeScript files.
You can use another way easier I think.
Step 1
Go with this steps
in your NuGet Manager.
Add Microsoft.AspNet.Web.Optimization
Add BundleTransformer.SassAndScss
Add LibSassHost.Native.win-x64 if you use system 64 bit.
LibSassHost.Native.win-x86
Step2
In BundleConfig.cs add this code in RegisterBundles methode.
var nullBulider = new NullBuilder();
var nullOrderer = new NullOrderer();
BundleResolver.Current = new CustomBundleResolver();
var commonStyleBundle = new CustomStyleBundle("~/Bundle/sass");
commonStyleBundle.Include("~/css/main.scss");
commonStyleBundle.Orderer = nullOrderer;
bundles.Add(commonStyleBundle);
Step 3
Add CSS folder in your project and add main.scss file sheet inside.
Step 4
In your view, you need to use System.Web.Optimization.
#using System.Web.Optimization
And link your style sheet
#Styles.Render("~/Bundle/sass").
Step 5
In Global.asax we need to add this line in Application_Start().
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
Or maybe you will find it already in your class if you use MVC templet.
And that is it your main.scss its work.
This is how you can add Sass to your Mvc app:
Download WebCompiler:
https://marketplace.visualstudio.com/items?itemName=MadsKristensen.WebCompiler&ssr=false#qna
Double click on the Vsix file to install it.
Right click on solution, Manage Nuget Packages
Download bootstrap.sass package (version 4 or above)
Right click on the bootstrap.scss file under Content folder you need and select Web Compiler - Compile File
The bootstrap.css file will be generated.
You can select any scss file to compile.
You can see the configuration (list of files to be compiled) in the compilerconfig.json file in the root folder.
Add the css file to the bundle.
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap/main.css",
"~/Content/site.css"));
If you need to customize bootstrap, add a main.scss file in the same folder as bootstrap.scss. Then compile it using Web Compiler.
main.scss:
/* import the necessary Bootstrap files */
#import "_functions.scss";
#import "_variables.scss";
/* make changes to the !default Bootstrap variables */
$body-color: green;
/* finally, import Bootstrap to set the changes! */
#import "bootstrap.scss";
This example includes all the files, but make sure you only add the files you need to make the css smaller.
I have the following code in my TS file...
require("jquery-ui/ui/widgets/datepicker.js");
require("angular-ui-date/dist/date.js");
When I run the code I get the following error...
Module not found: Error: Cannot resolve module 'jquery-ui/datepicker' in //code/my-app/node_modules/angular-ui-date/dist
# ./~/angular-ui-date/dist/date.js 3:66-97
So I ran tsd install jqueryui --save and then added the following to the same file as the require...
/// <reference path="../../../typings/jqueryui/jqueryui.d.ts" />
based on src/main/typescripts but I still get the same warning when running webpack
It seems to be a issue with latest version you are using. It has nothing to do with type definition. if you open angular-ui-date/dist/date.js you will find that it is requiring
require("jquery-ui/datepicker")
which does not exist
to workaround you could change it manually to require("jquery-ui/ui/widgets/datepicker") but that's a ugly solution i think.
There is also an issue on github and there is also suggestion for workaround
Please see the isse here
I added an alias to the resolve object in the webpack configuration file.
'resolve' : {
'alias' : {
'jquery-ui/datepicker' : 'jquery-ui/ui/widgets/datepicker'
},
},