-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use LESS files #165
Comments
In webpack: {
test: /\.less$/,
exclude: /node_modules/,
loader: 'raw-loader!less-loader'
} Then in your component: @Component({
styles: [ require('./filename.less') ],
}) Angular2 expects a string in the styles array, because it modifies the string to encapsulate the styling. Using style-loader/css-loader loads the css and inject to the html, without encapsulating, and doesn't return a string, raw-loader just load the file as string and pass it to less-loader, which also return a string. |
Yes, I know it, and I use the same config, what you mentioned, but this is still not working! |
Besides what @asafyish mentioned In package.json you need deps:
Then in component itself I use: const STYLES = require('!raw!less!./dashboard.less');
@View({
styles: [ STYLES ],
template: `<h1>Dashboard</h1>`
}) Cheers! |
@jbazinga make sure you add |
Thanks a lot, updated the issue text with the final solution. |
Opened #199 to consolidate these issues. |
I found an issue with the raw-loader loading less styles into a component. Images, references by the less source via a 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. |
Hi, |
Hi, it's working for me with stylus&postcss. package.json
webpack.common.js
app.component.ts
|
I ended up writing my own loader for this, which is kind of a hack that extracts the raw css from the output of the css-loader. I called it
|
@matthewlsawyer where can I find the component-style-loader? I'm stuck with this issue too. |
@tariknz I wrote it myself and we are currently using it at my company. Let me see if it is OK to open source it and I will respond here. |
@matthewlsawyer yeah that would be cool. I ended up using the ExtractTextPlugin but would be good to see how you did it. |
@tariknz @SDohle @bbottema I created a gist of the file we use. I created it by reverse engineering the output of the css-loader and converting it into a new export. If there is enough need of something like this I can publish on npm. https://gist.github.com/matthewlsawyer/002d16d7d9295a9706a8c78198bc9376 @tariknz How did you use the ExtractTextPlugin to achieve this? I was under the impression that Angular2 scoped the css per component using data attributes on the DOM and injecting them into the css. |
@matthewlsawyer yeah you're correct it did create a global style-sheet for me by using this plugin. Which I'm still wondering if this an acceptable approach or not. Used it here if you're interested: https://github.com/tariknz/wallofcolours Thanks a lot for the gist. |
@zaikin-andrew Hi ! |
@LeiwenL The issue was in mistake in the custom mixin into imported less file :) If loader can't compile a file it just doesn't give this file. |
Anyone know if there's a way to do this without the |
Never mind I figured it out: {
test: /\.less$/,
exclude: /node_modules/,
loaders: ["raw-loader", "less-loader"]
} and @Component({
selector: 'app',
template: '<h1>My First Angular 2 App!!!</h1>',
styleUrls: [ 'app.component.less' ]
}) |
What if I have one Mentioned
If I just use loader, add new entry point and extensions, I see that it gets compiled to css, but it is saved as
I would like to have |
@ndamnjanovic Did you get it figured out? I would like to know this as well. |
@derricksimpson it was a while ago, but we didn't make it at the end. our designer is doing it separately, not sure if it's not possible, or we just didn't have enough knowledge at that time. |
Nobody had fixed this issue ? and in webpack Same error chrome "display Uncaught Error: Expected 'styles' to be an array of strings." |
I would like to use less files in project.
UPDATE - Solution:
npm install --save-dev less less-loader
{ test: /.less$/, exclude: /node_modules/, loader: 'raw-loader!less-loader' }
The problem:
I tried this config in webpack.config.js:
and use it as home.ts:
but when I try to npm start, I got the following error:
My less file is very basic (copy it from lesscss.org startpage)
Thanks
The text was updated successfully, but these errors were encountered: