I have created jest code coverage report using command npx jest --coverage. It creates coverage directory in the root as below:
laravel_project
- app
- config
- coverage
-- lcov-report
--- index.html
--- prettify.js
--- prettify.css
When I open the index.html on my local the report looks proper as below. (JS & CSS created by the command loads properly)
I am trying to display the same code coverage report using a route as below.
Route::get('/reports/jest-coverage', function () {
return File::get(base_path('coverage/lcov-report/index.html'));
});
but CSS and JS included in the index.html breaks as Laravel doesn't allow to load resourses outside the public directory.
The JS & CSS files are included as below in the index.html:
<link rel="stylesheet" href="prettify.css" />
<link rel="stylesheet" href="base.css" />
<script src="prettify.js"></script>
How I can achieve this without modifying coverage directory?
Is there any way in Laravel to achieve this?
Related
I have a problem with my application not finding my static files. This however only happens on a certain level. As you can see from the code fragments below, the css, images, js, etc works on certain files and not on others. Not sure what I am missing here.
My Stack: Spring Boot, Thymeleaf
Part of my application.yml file:
server:
port: 8090
servlet:
context-path: /myapp
My application public resources directory structure:
/resources
/public
/css
/images
/js
My application template structure and where the styles and images work:
/resources
/templates/index.html (works)
/templates/admin/index.html (works)
/templates/admin/user/admin/showuser.html (does not work)
Code from /resources/admin/fragments/header.html (Used as a header file for other files)
<!DOCTYPE html>
<html>
<head>
<link href="css/mycss.css" rel="stylesheet">
Code from /resources/templates/index.html (works) (Does not include the header.html fragment)
<link href="css/mycss.css" rel="stylesheet">
Code from /resources/templates/admin/index.html (works) (Includes header.html as a fragment using Thymeleaf)
<!--/*/ <th:block th:include="/admin/fragments/header"></th:block> /*/-->
Code from /resources/templates/admin/user/admin/showuser.html (does not work) (Includes header.html as a fragment using Thymeleaf)
<!--/*/ <th:block th:include="/admin/fragments/header"></th:block> /*/-->
Not sure how to fix this.
Thank you!
When your urls don't begin with a slash /, they attempt to resolve the current directory. For example:
Page: /templates/index.html
Css: css/mycss.css
The browser tries to locate /templates/css/mycss.css
If the cases that don't work:
Page: /templates/admin/user/admin/showuser.html
Css: css/mycss.css
The browser tries to locate /templates/admin/user/admin/css/mycss.css
If you want to make sure your css works everywhere, you need to make sure the link points consistently to the correct location. I'm guessing something like this would work:
<link th:href="#{/css/mycss.css}" rel="stylesheet">
(Using Thymeleaf to add the context, and to make the path absolute.)
Problem:
I have a Hugo site with pretty standard setup. It uses asset pipeline to process SASS. It imports bootstrap, font-awesome, and also uses resources.ExecuteAsTemplate (please do check out main.css file). CSS resources are being generated properly (I checked resources/_gen/assets/scss/sass) but the .css file in public directory is an empty file. I am not able to find any problems in the code. See the code here, site here. I tried creating a new project with same head.html file and .scss files, and it generated CSS resources, and had them in the public directory properly.
Additional info:
Related files:
head.html
main.scss
Currently, I am not using PostCSS; just have the config file created. Would be replacing minify with postCSS on line 13 in head.html once empty .css file problem is solved.
Output of hugo version:
Hugo Static Site Generator v0.57.2-A849CB2D/extended linux/amd64 BuildDate: 2019-08-17T17:57:54Z
I would gladly provide any additional information if required. Please help!
In the head.html file, link tag is:
<link rel="stylesheet" integrity="{{ $css.Data.Integrity }}" href="{{ $css.Permalink }}">
Changing the link tag with following:
<link rel="stylesheet" href="{{ $css.Permalink }}" integrity="{{ $css.Data.Integrity }}">
fixes the issue.
It seems that Hugo requires user to first call .Permalink of the asset and then only other related functions or variables.
See related discussion on Hugo Discourse here.
I am developing a Web Application. I am using Laravel 5.3. I also want to use SASS. This is my first time of using SASS. I learned from this tutorial- http://blog.teamtreehouse.com/the-absolute-beginners-guide-to-sass. Now I am trying to integrate SASS with Laravel. I just started building project. So I decided to use this one - https://github.com/panique/laravel-sass.
I included this in composer.json
"require-dev": {
"panique/laravel-sass": "1.0"
}
I added this line in public/index.php
SassCompiler::run("scss/", "css/");
So my index.php in public folder look like this
Then I run "update composer" command in terminal. Installation worked well in terminal.
So now I need to try on SASS and make sure it is working or not.
So I created two file in public folder.
public/css/style.css
and
public/scss/style.scss
Then I created a view, hello.blade.php. This is the html.
<!DOCTYPE html>
<html>
<head>
<title>SASS</title>
<link rel="stylesheet" type="text/css" href="{{ url('css/style.css') }}">
</head>
<body>
<h1 class="heading">Let's sass. Just change color.</h1>
</body>
</html>
Then I added this lines in public/scss/style.scss
$red: #FF4848
.heading
color:$red
Then I configure Laravel route like this.
Route::get('hello', function () {
return View('hello');
});
When I access the URL from browser, it is giving me this error.
Fatal error: Uncaught Exception: parse error: failed at $color : red
line: 1 in
C:\xampp\htdocs\whatsuppathein\vendor\leafo\scssphp\scss.inc.php:4108
Stack trace: #0
C:\xampp\htdocs\whatsuppathein\vendor\leafo\scssphp\scss.inc.php(2761):
scss_parser->throwParseError() #1
C:\xampp\htdocs\whatsuppathein\vendor\leafo\scssphp\scss.inc.php(121):
scss_parser->parse('$color : red\r\n\r...') #2
C:\xampp\htdocs\whatsuppathein\vendor\panique\laravel-sass\sass-compiler.php(53):
scssc->compile('$color : red\r\n\r...') #3
C:\xampp\htdocs\whatsuppathein\public\index.php(50):
SassCompiler::run('scss/', 'css/') #4 {main} thrown in
C:\xampp\htdocs\whatsuppathein\vendor\leafo\scssphp\scss.inc.php on
line 4108
What is wrong with my code?
When I replace this line
SassCompiler::run("scss/", "css/");
with this
SassCompiler::run("public/scss/", "public/css/");
in public/index.php, it is not throwing error. But not changing any CSS. Not changing the font color.
Laravel uses gulp to transpile dependencies and it comes built it when you do npm install from your project direcftory.
Open up your resources/scss/app.scss file and you can perform #import statments to your own files.
The gulp.js file in your project's root directory contains the sass transpiling.
I get an Error Message with laravel 5, which I don't understand.
Next exception 'ErrorException' with message 'File build/css/all.css not
defined in asset manifest.
I haven't installed any asset pipeline or something. Just used elixir to compile, minify and version the scss-file to all.css and included it into the master view with <link rel="stylesheet" href="{{ elixir("css/all.css") }}">
What is this 'asset manifest' and how to fix this error?`
The question is of course what you want to achieve.
If you simply put all.css file into the public/css directory and you want to display this file, you can use:
<link rel="stylesheet" href="{{ asset('css/all.css') }}" />
However if you plan to modify this file and you don't want to have caching issues, you can put this all.css file again into public/css then put into gulpfile.js:
var elixir = require('laravel-elixir');
elixir(function(mix) {
mix.version('public/css/all.css');
});
Now you'll need to run:
gulp
in your terminal, and now you can use
<link rel="stylesheet" href="{{ elixir('css/all.css') }}" />
as you previously did in your HTML.
It will create public/build/ folder with rev-manifest.json (this file is missing in your case).
I would recommend you to watch Managing assets Laracasts episode to understand it a bit better.
Same issue here!! I solve it by creating production version of css. I update gulefile.js as bellow,
elixir(function(mix) {
mix.sass('app.scss').version('css/app.css').browserify('app.js');
});
Then run following command which will create rev-manifest.json file in public/build directory.
gulp --production
Good luck!!
I am a absolute beginner of CodeIgniter, Now I was creating a simple project with CI. But I don't know how I can call a file that has existed in core folder.
Core folder is like the following
/core/bootstrap/bootstrap.css
I want to call bootstap.css from my view/admin/index.php
How I can call it?
I already try it like the following
<link href="/application/core/bootstrap/bootstrap.css" rel="stylesheet" media="screen">
but it still doesn't work.
You should not put your CSS files in the core folder. Best practice with CI is the following:
- application
- assets
-- css
-- js
-- images
- system
-- <all CI folders here>
Use a URL helper to point to the assets folder like:
function asset_url(){
return base_url().'public/';
}
more info on url_helpers
Then you can point to your assets in your view like this:
<link rel="stylesheet" href='<?php echo asset_url()."css/YOUR_FILE.css" ?>'/>
Look at documentation and read about url_helper.
Use internal links with function site_url() or base_url()
First of all I will not put my css files in the core folder.
I will create folder which is in the same level as in the "application" and "system" folder.
Secondly, you need to configure the base url at application/confi/config.php like
$config['base_url'] = 'http://localhost/NV/';
With in the folder "NV", I have my CI files such as "application" and "system".
Then in the view I will just use
<link rel="stylesheet" href="<?php echo base_url();?>css/ace.min.css"/>
In this case, the "CSS" folder resides as in the same level as "application" and "system" folders.