PatrickJS-starter icon indicating copy to clipboard operation
PatrickJS-starter copied to clipboard

Using bootstrap 4 mixins with angular2

Open regenrek opened this issue 10 years ago • 11 comments

Hi,

don't know if its the right place to ask here but I'm trying to get this repo work with bootstrap 4 mixins.

I followed the wiki bootstrap 4 guide and everything looks good.

But if I have an component for instance

home.component.ts

@Component({
  selector: 'home',
  styleUrls: ['./home.style.scss'],
  templateUrl: './home.template.html'
})

and home.style.scss

@include media-breakpoint-up(md) { .dosomething { padding: 0px; } }

I get 'No mixin named media-breakpoint-up'.

If i add the following line to home.style.scss it works. But I don't know it it's the right thing todo.

@import "./node_modules/bootstrap/scss/_variables.scss";
@import "./node_modules/bootstrap/scss/mixins/_breakpoints.scss";

So is it possible to inject _breakpoints.scss (mixins) and _variables.scss global or if its needed? Shouldn't webpack handle this case?

Regards

regenrek avatar Aug 29 '16 18:08 regenrek

I got this to work by importing @import "../../../node_modules/bootstrap/scss/bootstrap-grid.scss"; instead of the breakpoints directly. The Bootstrap-Grid file does include the breakpoints along with other pieces.

jshamley avatar Aug 29 '16 18:08 jshamley

@jshamley True. Thank you. bootstrap-grid.scss looks better. But you need still manually import the scss files right? Where do you import the scss - in every component where you need the mixins or globally (maybe in app.styles?)

Regards

regenrek avatar Aug 29 '16 19:08 regenrek

@regenrek I have been importing them per component SCSS file. I have only needed those mixins a couple times so far so I didn't take the time to import globally.

jshamley avatar Aug 29 '16 19:08 jshamley

A bit off topic: but you can use all the import Sass files with module syntax by prefixing it with ~ import "~boostrap/scss/bootstrap-grid.scss".

katallaxie avatar Aug 29 '16 19:08 katallaxie

@katallaxie That would be great but I'll get Cannot find module "~bootstrap/scss/bootstrap-grid.scss"

EDIT: y I know its offtopic but I'm looking for some best practice scenario with this repo. Thought mixins would get injected automatically if we need them

regenrek avatar Aug 29 '16 19:08 regenrek

@regenrek check the path, this was just an example. https://github.com/jtangelder/sass-loader#imports

Also includePaths provides node-sass with a hint to resolve the imports. https://github.com/sass/node-sass#includepaths

It is difficult to maintain mixins, as the the sass files are processed on the file entry. You could have something like a facade.scss that you could simply share.

katallaxie avatar Aug 29 '16 19:08 katallaxie

@katallaxie yes. tried to include it in the home.component.ts. Works so far.

home.style.scss @import "~bootstrap/scss/bootstrap-grid.scss";

regenrek avatar Aug 29 '16 19:08 regenrek

@regenrek have you seen https://ng-bootstrap.github.io/ ? It uses the latest RC.6 and it possible just to import one like any other new ngModules

ps: IMO ng-bootstrap is the subject for some new webpack-starter branch of this repo ?

codespicelabs avatar Sep 02 '16 17:09 codespicelabs

+1 for ng-bootstrap branch

alvipeo avatar Sep 03 '16 06:09 alvipeo

I think should be sufficient to have this as a practice in the README. @regenrek could you do that and do a PR?

katallaxie avatar Sep 03 '16 07:09 katallaxie

⚠WARNING⚠ @import "../../../node_modules/bootstrap/scss/bootstrap-grid.scss"; is not a good solution! This is causing Bootstrap's grid CSS to be regenerated every place you use this import. You only want the mixins, which by themselves don't add to any generated CSS output. Here is the best solution.

stamminator avatar Aug 30 '18 18:08 stamminator