-
Notifications
You must be signed in to change notification settings - Fork 519
Css preprocessor? #132
Comments
This is easily handle by adding Sass or Less loader in webpack.config. Or you propose to made it in yo-templates? This possibly should be an option of generator. |
Yes indeed an extra option in the yeoman thing |
Thanks for the suggestion. I'm not sure whether we'll handle it by adding further options to the generator, or by adding docs describing how to do it. But it should be really straightforwards - just amend your |
I highly recommend that you make it an option in the generator, otherwise you will get a lot of issues for people trying to set it up themselves. |
I'm actually having trouble with getting sass to work with prerendering. Does anyone have a working EDIT: I'm no webpack expert, but I made it work. I don't really understand the implications of the following settings, maybe someone can shed some light. Based on webpack-contrib/css-loader#59 {
test: /\.scss$/,
include: /ClientApp/,
loaders: [
'css-loader/locals?module&localIdentName=[name]__[local]___[hash:base64:5]',
'sass-loader'
]
} |
An option in the generator would go awesome. I'm having trouble getting it to work for less. I added the loader to the It works when i run 'webpack' directly at the CLI, but when I run 'dotnet run' there's an exception in the middleware when I make the first page request.
Has anyone got this working? |
@shobman did you check my last comment? I couldn't make it work with |
I'm sorry, I was terribly wrong. The issue here is that we need different webpack bundles for both configurations (we need different module loaders for sass browser vs sass server as the webpack maintainers show here), but this is not supported by aspnet-webpack. See how the configuration is tweaked to work in the backend here: https://github.com/aspnet/JavaScriptServices/blob/master/src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/src/LoadViaWebpack.ts#L37. And if you try to use an array as configuration (allowed by webpack as seen here) you get this exception https://github.com/webpack/webpack/blob/8ff6cb5fedfc487665bb5dd8ecedf5d4ea306b51/lib/MultiCompiler.js#L39. This is effectively breaking one of webpacks features, and it makes me wonder if this is the correct approach. Maybe instead of overriding the configuration we could define two configurations, and let aspnet-webpack search for the one it needs. I'm close to making this work by manually tweaking |
Well, I made it work, but not 100% with angular2. Either you:
Steps:
Hope someone figures out how to make this fully work! |
It almost works using If you try to use |
@SteveSandersonMS @laskoviymishka I know you're not providing a built-in css-preprocessor support, but maybe you could take a look at the issue we're having when doing it ourselves? The "cannot find module" error looks like a bug in <app
asp-prerender-webpack-config="webpack.config.js">Loading...</app> Do you want me to open a new issue? Maybe provide a repro? I think you'll hit the issue pretty easily if you try to set up a project with sass, but let me know :). |
@tinchou Are you on the current version of I ask this because I just tried setting up a CSS preprocessor (I used LESS), and in all cases it just worked fine. It works both with
I see - thanks for letting me know! For For
... and then when using prerendering, you could specify which config you want to use to build the boot module, e.g.:
What do you think? |
@SteveSandersonMS I had just updated to RC5, and it's not yet supported in universal (see angular/universal#511). I'll try it when they release an updated package and I'll post here. |
I've added some detailed docs on ways to configure LESS/SASS/etc loading: https://github.com/aspnet/JavaScriptServices/tree/dev/src/Microsoft.AspNetCore.SpaServices#example-a-simple-webpack-setup-that-builds-less Closing now as I'm fairly convinced this works (it certainly does work as documented). But if anyone finds issues with LESS and Angular 2 RC5 in particular, please file a new issue with repro info! |
Thank you very much! I'm still waiting on angular universal to update their
|
@SteveSandersonMS
If I run webpack manually, I could see the style bundle output correctly. |
Related issue: #241 I removed my webpack config for preprocessing less files and just tried to import relative css file, and I got the same error. Below is the diff between my changes and the sample code:
|
That is as expected. It works to import them in You should either reference your client-only resources from |
That makes sense. Thanks for the explanation. |
@tuan Great that you got it working! Would you be able to share your fix slightly more in depth? I'm struggling with the exact same problem, but being new to Webpack, I don't quite have enough context to implement your fix. Thanks :) |
@paulinfrancis
This does not work if I import sass files in a file that is rendered on the server because of the reason Steven pointed out.
Note: I don't use extract text plugin in this config. Also, I use In Home\index.html, I use the new webpack.config.prerender.js instead. Here's the diff
Hope this helps! |
Hey guys, I finally updated my packages and I'm ready to sort this out. @SteveSandersonMS says In my scenario, I'm trying to pass SCSS to Angular 2, and the only reason I need to use @Component({
selector: "nav-menu",
template: require("./nav-menu.component.html"),
styles: [require("css-loader!sass-loader!./nav-menu.component.scss").toString()],
})
export class NavMenuComponent {
//.... If I were writing the style directly in the So, if it is really true that My next step is to download a starter template that doesn't use ASP.NET (like this one https://github.com/angular/universal-starter) and check if it does work. @MarkPieszak I've seen you collaborating on integrating this and Universal, so maybe you can share your thoughts? Thanks! :) |
If this solution needs to use require to load the .html and .css/.scss files, doesn't that mean I can't use other third-party components that don't use require? That would be a big problem. |
@tinchou @RobCannon You should be able to do sass with require & loaders taking advantage of everything if I'm not mistaken. Are you not able to right now? The reason we use require is to simply inject the raw text from the file and insert it into
If you have the loaders set up correctly, I believe roughly like so:
I'd have to double check the exact setup. |
@MarkPieszak, thanks for your quick reply! This is what I'm trying to use and that's not working with ASP.NET. The error is the one above: the server can't find the css loader and fails to prerender. |
@tinchou Yes, you're right! I was conflating |
Awesome! Feels good not to be crazy after all 😜 On Tue, Sep 20, 2016, 07:19 Steve Sanderson notifications@github.com
|
OK, I tracked it down. It was an incompatibility between Instead of trying to get I've published an update to Also I'm changing the default Angular2Spa template so that it uses In conclusion, thanks @tinchou for persisting with pointing this out - things are much better now this is fixed! |
Dude it works great. Thanks to you! On Tue, Sep 20, 2016 at 12:57 PM Steve Sanderson notifications@github.com
|
Consider adding a css preprocessor option like Sass or Less.
Because who writes plain old css these days?
The text was updated successfully, but these errors were encountered: