Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does a `~` tilde in a CSS `url()` do?

E.g. @import url("~./foobar");

Saw it here, not sure if it's some package specific thing or if it's actual CSS syntax.

like image 256
ahstro Avatar asked Sep 16 '16 16:09

ahstro


People also ask

What does tilde mean in SCSS import?

Subtask of 1 issue (0 unresolved) WEB-17533 Support for webpack resolve.modulesDirectories. 34 13. Webpack lets you specify the project's root and then tilde (~) is used to import scss files relative to the root set in the webpack config file.

What does @import mean in CSS?

The @import rule allows you to import a style sheet into another style sheet. The @import rule must be at the top of the document (but after any @charset declaration). The @import rule also supports media queries, so you can allow the import to be media-dependent.


1 Answers

The CSS @import path <url> is usually relative to the current working directory.

So using the prefix ~ at the start of the path tells Webpack's css-loader to resolve the import "like a module", starting from the node_modules directory.

What that means is that if you have a node module called normalize installed, and you need to import a css file from within it named /normalize.css, you can do that with:

@import "~normalize/normalize.css"; 

In your linked example, inside font-loader/example/test.js there is an import of a module called font-boon.

var boon = require('./font-boon'); 

Inside of font-loader/example/test.css the font-boon module is @imported so that it is available in text.css.

@import url("~./font-boon");

like image 126
ksav Avatar answered Oct 02 '22 05:10

ksav