Webpack resolve-url-loader resolving incorrect paths - npm

I'm making use of the resolve-url-loader which is working great for importing third party stylesheets that are in turn linking to their own assets.
However, i'm struggling to understand how in the instance below my reference to owl.jpg from app.scss manages to successfully resolve?
Folder structure:
src/
|
|- index.html
|
|-img/
| owl.jpg
|
|- scss/
| app.scss
|
|-js/
| app.js
app.scss
These incorrect paths to the asset still seem to resolve?
.owl {
background: url('owl.jpg');
}
.owl {
background: url('/owl.jpg');
}
.owl {
background: url('img/owl.jpg');
}
Surely the path should only resolve with the below path?
.owl {
background: url('../img/owl.jpg');
}
Am i missing something? Is the resolve-url-loader clever enough to resolve incorrect paths??

You have to compile your scss file to css, browser works only with .css files. Then choose the output folder, i guess it can be src/css, and then enter a correct path in your css depending on images folder.
If webpack compiles scss files without errors, it just could be incorrect url to image. If correct, background-size property should be added with 100% 100% parameters.
.owl {
background-image: (path/to/image.img);
background-size: 100% 100%;
}

Related

How to reference `baseUrl` in the `<style>` section of a vue.js SFC?

How may we reference baseUrl in the <style> section of a vue.js SFC?
/src/views/Home.vue
<style scoped>
#import url(<%= BASE_URL %>static/required_styles.css); // does not work
</style>
Directory structure:
|--public
| --static
| --required_styles.css
|--src
| --views
| --Home.vue
It's not clear how to do this from the docs on static asset handling:
https://cli.vuejs.org/guide/html-and-static-assets.html#the-public-folder
The public folder is for files that you want to be served directly on the server without going through webpack. An example would be minified css who's styles you use. In that case you would just add the css path to vue.config.js or the header of index.html. If you are importing in the styles tag the css will be pull through your build process (e.g. webpack) when the component is compiled. This means you should not put the .css file in the public folder, and should use a relative path for the import.

CSS variables not resolving when file is imported into another file

I am working on a project where I am developing a set of UI components for developers to use to build out their sites. I have created an NPM package which consists of just the CSS required to implement an Accordion component.
I installed my css-accordion-component as a development dependency via npm install to a React project created using create-react-app. My Accordion.js file in the React project imports the css-accordion package from node_modules like so:
import "css-accordion-component/lib/accordion.css";
This does bring the styles into my project but none of the CSS Variables defined and used in the file are resolving. The CSS file looks like so:
:root {
--Accordion-bgColor: #fff;
};
.Accordion {
background-color: var(--Accordion-bgColor);
}
I believe it may be because the React project built with create-react-app is not running this imported css file through its post-css plugins. There seems to be a lot of out of date advice online about how to correctly configure Webpack to use PostCSS. Any advice would be really great.
:root {
--Accordion-bgColor: #fff;
};
^^ The semi-colon here proved to be the problem. It caused the whole :root block to fail to render.

Module not found: Error: Can't resolve 'assets/img vue.js

I have following structure:
-src
-assets
-css
-img
-js
In my style.css I have this line:
background: url(~assets/img/arrows.png) no-repeat;
And get this error
Module not found: Error: Can't resolve 'assets/img/arrows.png'
what do I do?
I tried to write ./assets/, ../assets/ , ./src/assets still doesn't work
If you've imported the css file in App.vue or any other .vue file make sure the url is relative to that *.vue file
This issue can come up in Nuxt.js projects. If you're seeing this issue there, you'll have to either use a tilde (~) with no slash in front of the absolute path or you have to use a tilde and an at sign (#), so either this:
background-image: url('~assets/img/arrows.png');
Or this:
background-image: url('~#/assets/img/arrows.png');

How to deal with relative image path in subdirectories when using #import scss for IntelliJs autocompletion?

I like the autocompletion feature of Webstorm, Phpstorm and Intellij and the other jetbrain-products. It doesn't work however if I have a structure like this:
img/my-img.jpg
sass/main.scss
sass/component/_component.scss
// sass/main.scss:
#import "/component/component"
// _component.scss:
.class{
// => autocomplete doesn't work here as desired <=
// how intellij completes it
background: url(../../img/my-img.jpg)
// what i would like to have instead
background: url(../img/my-img.jpg)
}
Is there some way of telling IntellJ how to use the sass folder as base for the autocompletion of images and to get rid of the annoying error notice?
You can mark img folder as resourse root.
From jetbrains documentation:
Files under a folder marked as Resource Root can be referenced relative to this folder.

IntelliJ 12 won't pull in Sass variables

I have a very basic Ruby on Rails installation. I have installed the bootstrap-sass gem, have the 'bootstrap-sass' ~> 2.3.1.0 in my Gemfile and ran bundle install. Restarted all applications. I have a style.css.scss file in app > assets > stylesheets which #imports 'bootstrap'; as well as the responsive. Those styles actually get pulled into my app, because they style the front-end. However, when I try to use a variable or mixin, I get the error in the image attached, as well as IntelliJ telling me it cannot find the variable. I'm new at this whole process, so I'm just trying to understand what's needed to resolve it.
I am using Ruby 2.0.0 and Rails 3.2.13rc2
https://docs.google.com/file/d/0BwMz3RH42HtQb0U1TXdHTVF0QjQ/edit?usp=sharing
#import "bootstrap";
body {
padding-top: 60px;
}
#import 'bootstrap-responsive';
.footer {
margin-top: 50px;
color: $greyLight;
a {
color: #e5e5e5;
}
}
here is a link to the live dev site on heruko, without use of the variables:
http://shrouded-ocean-4277.herokuapp.com/
EDIT: in my vendor/assets/stylesheets folder, there is no bootstrap folder or _mixins or _variables files. Should these have been installed when I placed the gem in the Gemfile and did an bundle install?
EDIT: adding my github: https://github.com/ChrisSki/omrails
Regarding your edit, the bootstrap will not be in vendor, but in a .gem file located somewhere inside your Ruby installation.
I set up a similar application recently, following this guide. I have 2 .css.scss files, one which includes and overrides parts of bootstrap, and the other one which contains my application's style (not directly related to Bootstrap). If you look at the second file, you can see that I imported bootstrap/variables because I needed to have access to some of Bootstrap's variables, and it works like a charm.
What I don't understand is why your original screenshot complains about something named variables, which I cannot see in your SCSS file... Have you tried bootstrap/variables instead?
EDIT:
I just cloned your repo, started the server and hacked style.css.scss. I think you made a typo in your tests :)
h1 {
color: $greyLight; /* Does not work!! */
color: $grayLight; /* Works :) */
}
You should declare your variables before you import bootstrap, then you can use the variables in your scss.
For example, here's how I use variables in my rails app:
/************************ CSS Variables ***************************/
$myColor: #0F851C;
/************************ Import Bootstrap ********************************/
#import 'bootstrap';
body { padding-top: 80px; }
#import 'bootstrap-responsive';
Just define your variables at the top of your scss, then import bootstrap. Then in your scss, you can use those variables like this:
#myDiv {
color: $myColor;
}
Hope this helps!