Is there a way to set a common image path for LESS files?
Try using string interpolation for things like this. Look for “variable interpolation” in docs.
@base-url: "http://assets.fnord.com";
background-image: url("@{base-url}/images/bg.png");
Can less.js handle relative paths for images?
Try quoting the URL, I always do it this way to keep it neat though,
@header-image: "../img/header.jpg";
background: url(@header-image);
Also, the URL code can be seen on github. Looks like it is added if you are running in a browser.
Relative path of node_modules for LESS @import
You can achieve this by installing less-loader and add it into webpack.
How to do it:
https://www.npmjs.com/package/less-loader#webpack-resolver
Example:
@import "~font-awesome/css/font-awesome.min.css";
Angular 2 img src in a relative path
I am using webpack and have been able to overcome this issue by require
ing the image in the component as a variable and using this in my template.
This is because during the bundling phase webpack will load the resource and store the correct URL and calling require at runtime will get this correct URL to pass to the template.
Example
Using the following directory structure
app/
header/
header.component.ts
header.component.html
assets/
logo.png
...
header.component.ts
...
@Component({
selector: 'header',
templateUrl: './header.component.html', // Auto required by webpack
})
export class HeaderComponent {
private LOGO = require("./assets/logo.png");
constructor() {};
}
header.component.html
<div>
<img [src]="LOGO" />
</div>
Admittedly this binds the component and template but the require needs to be in the component so that webpack is able to analyse and load it when bundling.
With this approach I have packaged my module using npm and installed and used it in another project - which also uses webpack.
I am yet to test with SystemJS.
Related Topics
Is There a Reason Why CSS Doesn't Support Ids and Classes, Starting from Numbers
Xhtml/Css: How to Make Inner Div Get 100% Width Minus Another Div Width
Changing Three.Js Background to Transparent or Other Color
How to Remove Space (Margin) Above HTML Header
Differencebetween the Hidden Attribute (Html5) and the Display:None Rule (Css)
How to Ensure That Text Is Inside Rounded Div
How Does Object-Fit Work with Canvas Element
Two Divs, One Fixed Width, the Other, the Rest
How to Customize the HTML5 Input Range Type Looks Using CSS
Less and Bootstrap: How to Use a Span3 (Or Spanx [Any Number]) Class as a Mixin
Does a Background-Attachment of Fixed Work in iOS5
Minmax Fails (Invalid Property Value)
Transform-Origin for CSS Animation on Svg Working in Chrome, Not Ff
How to Add Different CSS Style to Every Nth Element, Depending on N Using Less