How to use LESS files
See original GitHub issueI would like to use less files in project.
UPDATE - Solution:
- install npm dependencies:
npm install --save-dev less less-loader
- add less extension to resolve.extensions section:
resolve: {
// ensure loader extensions match
extensions: ['','.ts','.js','.json', '.less', '.css', '.html']
},
- add a loader like:
{ test: /.less$/, exclude: /node_modules/, loader: 'raw-loader!less-loader' }
- and now can use like:
@Component({
styles: [ require('./filename.less') ],
...
})
The problem:
I tried this config in webpack.config.js:
{ test: /\.less$/, loader: "raw-loader!less-loader"}
and use it as home.ts:
@Component({
selector: 'home',
directives: [ FORM_DIRECTIVES ],
pipes: [],
styles: [ require('./home.less') ],
template: require('./home.html')
})
but when I try to npm start, I got the following error:
ERROR in ./src/app/home/home.less
Module build failed: visitors[i].run is not a function
@ /home/ubuntu/workspace/browserclient/src/app/home/home.less (line null, column -1)
near lines:
@ ./src/app/home/home.ts 23:21-43
My less file is very basic (copy it from lesscss.org startpage)
@base: #f938ab;
.box-shadow(@style, @c) when (iscolor(@c)) {
-webkit-box-shadow: @style @c;
box-shadow: @style @c;
}
.box-shadow(@style, @alpha: 50%) when (isnumber(@alpha)) {
.box-shadow(@style, rgba(0, 0, 0, @alpha));
}
.box {
color: saturate(@base, 5%);
border-color: lighten(@base, 30%);
div { .box-shadow(0 0 5px, 30%) }
}
Thanks
Issue Analytics
- State:
- Created 8 years ago
- Reactions:2
- Comments:24 (1 by maintainers)
Top Results From Across the Web
Less.js: Getting started
Less (which stands for Leaner Style Sheets) is a backwards-compatible language extension for CSS. This is the official documentation for Less, the language...
Read more >LESS CSS - Beginner's Guide - Hongkiat
LESS comes with a less.js file which is really easy to deploy in your website. Create a stylesheet with .less extension and link...
Read more >How to create a LESS file and how to compile it - GeeksforGeeks
Step 1: Go to your project folder, create a subfolder named CSS and then create a file named styles.less inside it.
Read more >What is a Less file? - Stack Overflow
Less is basically a CSS-like language with additional capabilities that can be compiled to CSS using a preprocessor.
Read more >Less CSS Pre-Processor Tutorial - YouTube
... look at all of the basics and fundamentals of the Less CSS pre-processor/pre-compiler. Less gives you powerful features to take advanta.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I found an issue with the raw-loader loading less styles into a component. Images, references by the less source via a
url
will not be resolved by webpack.For example, the component:
And in style.less:
Webpack config:
The raw-loader will not try to resolve this url, that seems to be the responsibility of the css-loader. As far as I’m aware the css-loader doesn’t work with angular components.
Nobody had fixed this issue ?
styleUrls: ['./login.component.less'],
and in webpack use: [‘raw-loader’, ‘css-loader’, ‘less-loader’]
Same error chrome “display Uncaught Error: Expected ‘styles’ to be an array of strings.”