Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.

Commit b4d3661

Browse files
seanforyou23jeff-phillips-18
authored andcommitted
feat(doc): provide basic example for scss with webpack (#1150)
improve readme to include example of webpack config
1 parent 754508a commit b4d3661

File tree

1 file changed

+64
-29
lines changed

1 file changed

+64
-29
lines changed

README.md

Lines changed: 64 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ If you wish to contribute to PatternFly, please follow the instructions under "C
2020

2121
PatternFly can be installed and managed through [NPM](https://www.npmjs.com/). To do so, either add `patternfly` as a dependency in your `package.json` or run the following:
2222

23-
```
23+
```sh
2424
npm install patternfly --save
2525
```
2626

@@ -30,15 +30,15 @@ PatternFly stays up to date with the Node LTS [Release Schedule](https://github.
3030

3131
PatternFly can be installed and managed through [Bower](http://bower.io/). To do so, either add `patternfly` as a dependency in your `bower.json` or run the following:
3232

33-
```
33+
```sh
3434
bower install patternfly --save
3535
```
3636

3737
#### Using Wiredep?
3838

3939
Are you using [Wiredep](https://github.com/taptapship/wiredep)? PatternFly's CSS includes the CSS of its dependencies. As a result, you'll want to add the following to your [Wiredep configuration](https://github.com/taptapship/wiredep#configuration) so you don't end up with duplicate CSS.
4040

41-
```
41+
```javascript
4242
exclude: [
4343
"node_modules/patternfly/node_modules/patternfly-bootstrap-combobox/css/bootstrap-combobox.css",
4444
"node_modules/patternfly/node_modules/bootstrap-datepicker/dist/css/bootstrap-datepicker.css",
@@ -61,6 +61,41 @@ exclude: [
6161
**Patternfly now supports Sass natively!**
6262
Sass is included in the `dist/sass` directory. Just add `node_modules` to your build tool's Sass include paths then `@import 'patternfly/dist/sass/patternfly';` in your Sass to get started!
6363

64+
#### Using Webpack?
65+
There are two touch points for integrating patternfly sass: one in your webpack config, and another in your sass. Below is an example module rule for loading patternfly .scss files using webpack.
66+
67+
```javascript
68+
module: {
69+
rules: [
70+
{
71+
test: /\.scss$/,
72+
use: [
73+
{
74+
loader: 'sass-loader',
75+
options: {
76+
includePaths: [
77+
// teach webpack to resolve these references
78+
path.resolve(__dirname, 'node_modules', 'patternfly', 'dist', 'sass'),
79+
path.resolve(__dirname, 'node_modules', 'bootstrap-sass', 'assets', 'stylesheets'),
80+
path.resolve(__dirname, 'node_modules', 'font-awesome-sass', 'assets', 'stylesheets')
81+
]
82+
}
83+
}
84+
]
85+
}
86+
]
87+
}
88+
```
89+
90+
With webpack configured, just set the asset-path related variables and you're off!
91+
92+
```scss
93+
$img-path: '~patternfly/dist/img/';
94+
$font-path: '~patternfly/dist/fonts/';
95+
$icon-font-path: '~patternfly/dist/fonts/';
96+
@import '~patternfly/dist/sass/patternfly';
97+
```
98+
6499
Please note that the [patternfly-sass](https://github.com/patternfly/patternfly-sass) is no longer supported and will not include any features or fixes introduced after Patternfly 3.23.2. However, the [patternfly-sass](https://rubygems.org/gems/patternfly-sass) Rubygem is maintained further and built from this repository.
65100

66101
### AngularJS
@@ -93,13 +128,13 @@ The development includes the use of a number of helpful tasks. In order to setup
93128

94129
To do this clone, and change directories into PatternFly:
95130

96-
```
131+
```sh
97132
cd [PathToYourRepository]
98133
```
99134

100135
then
101136

102-
```
137+
```sh
103138
npm install
104139
```
105140

@@ -115,13 +150,13 @@ Additionally you may need to install the grunt command line utility. To do this
115150

116151
Test pages are optionally generated using [Jekyll](http://jekyllrb.com/). To use jekyll to build the test pages, ensure Ruby is installed and available then run:
117152

118-
```
153+
```sh
119154
npm run jekyll
120155
```
121156

122157
or
123158

124-
```
159+
```sh
125160
gem install bundle
126161
bundle install
127162
```
@@ -135,7 +170,7 @@ Next, set the environment variable PF_PAGE_BUILDER=jekyll. eg.:
135170

136171
Anytime you pull a new version of PatternFly, make sure you also run
137172

138-
```
173+
```sh
139174
npm update
140175
```
141176

@@ -145,13 +180,13 @@ so you get the latest version of the dependencies specified in package.json.
145180

146181
A local development server can be quickly fired up by using the Gruntjs serve task:
147182

148-
```
183+
```sh
149184
npm start
150185
```
151186

152187
or
153188

154-
```
189+
```sh
155190
grunt serve # will build first by default
156191
grunt serve --skipRebuild # flag would allow you to skip the rebuild to save some time
157192
```
@@ -168,7 +203,7 @@ PatternFly uses the [semantic-release tool](https://github.com/semantic-release/
168203

169204
We have configured the [commitizen tool](https://github.com/commitizen/cz-cli) to assist you in formatting your commit messages corrctly. To use this tool run the following command instead of `git commit`:
170205

171-
```
206+
```sh
172207
npm run commit
173208
```
174209

@@ -212,13 +247,13 @@ The tool will prompt you with several questions that it will use to correctly fo
212247

213248
In development, styling is written and managed through multiple Less files. In order to generate a CSS file of all styling, run the build Gruntjs task:
214249

215-
```
250+
```sh
216251
npm run build
217252
```
218253

219254
or
220255

221-
```
256+
```sh
222257
grunt build
223258
```
224259

@@ -227,14 +262,14 @@ This task will compile and minify the Less files into CSS files located at `dist
227262
### Less to Sass Conversion
228263
Any time style changes are introduced, the Sass code will need to be updated to reflect those changes. The conversion is accomplished as part of the build, but in order to test the CSS you will need to build it from Sass:
229264

230-
```
265+
```sh
231266
npm start -- --sass
232267
```
233268
*Note the extra ` -- ` between `npm start` and the `--sass` flag. This syntax passes the flag on to the underlying grunt process instead of the npm command itself.*
234269

235270
or
236271

237-
```
272+
```sh
238273
grunt build --sass
239274
```
240275

@@ -249,7 +284,7 @@ Sass and Less do not have perfect feature parity, which can sometimes throw a wr
249284
#### Non-parametric Mixins
250285
Sass does not support non-parametric mixins in the same way that Less does. Mixins must be explictly declared in Sass, whereas any class definition in Less can be used as a non-parametric mixin. Sass does not have a feature that perfectly parallels this behavior, so we have to use the closest thing which is the `@extend` statement. However, an edge case exists where `@extend` statements are not allowed within media queries in Sass. This creates a scenario where uncompilable Sass code can be generated from perfectly acceptable Less. For example:
251286
**Less:**
252-
```
287+
```less
253288
.applauncher-pf {
254289
.applauncher-pf-title {
255290
.sr-only();
@@ -262,7 +297,7 @@ Sass does not support non-parametric mixins in the same way that Less does. Mixi
262297
```
263298

264299
**Converts to Sass:**
265-
```
300+
```scss
266301
.applauncher-pf {
267302
.applauncher-pf-title {
268303
@extend .sr-only;
@@ -277,7 +312,7 @@ Sass does not support non-parametric mixins in the same way that Less does. Mixi
277312
This breaks for two reasons. We cannot use the `@extend` statement directly inside a media query, and even if we are able to work around that by making applauncher-pf into a mixin and using the `@include` directive, `.applauncher-pf .applauncher-pf-title` uses the `@extend` directive, which would still fall within the media query via the mixin invocation. To fix this, the Less would need to be adjusted like this:
278313

279314
**Less**
280-
```
315+
```less
281316
// Explicitly define a non-parametric sr-only mixin.
282317
.sr-only() {
283318
// sr-only rules;
@@ -304,7 +339,7 @@ This breaks for two reasons. We cannot use the `@extend` statement directly insi
304339
```
305340

306341
**Converts to Sass:**
307-
```
342+
```scss
308343
@mixin sr-only() {
309344
// sr-only rules
310345
}
@@ -327,42 +362,42 @@ This breaks for two reasons. We cannot use the `@extend` statement directly insi
327362
#### Tilde-Escaped Strings
328363
Strings that are escaped using the tilde in Less get converted to the Sass `unquote()` function. This causes Sass compilation issues when using escaped strings inside native CSS functions like `calc()`. Here is what happens:
329364
Less:
330-
```
365+
```less
331366
height: calc(~"100vh - 20px");
332367
```
333368
Converts to Sass:
334-
```
369+
```scss
335370
height: calc(unqoute("100vh - 20px")):
336371
```
337372
Which compiles directly to CSS and does not work as expected:
338-
```
373+
```css
339374
height: calc(unqoute("100vh - 20px")):
340375
```
341376

342377
To fix this, move the tilde operator outside of the `calc()` statement:
343378

344379
Less:
345-
```
380+
```less
346381
height: ~"calc(100vh - 20px)";
347382
```
348383
Converts to Sass:
349-
```
384+
```scss
350385
height: unqoute("calc(100vh - 20px)");
351386
```
352387
Compiles to CSS:
353-
```
388+
```css
354389
height: calc(100vh - 20px);
355390
```
356391

357392
#### Comma Separated CSS Rules
358393
Using complex, comma separated rules in things like box shadows or backgrounds will cause conversion problems if they are not properly escaped. These rules should be escaped, and mixins and variables should not be used inline. For example, this statement should not be used in Less:
359-
```
394+
```css
360395
box-shadow: inset 0 1px 1px fade(@color-pf-black, 7.5%), 0 0 6px lighten(@state-danger-text, 20%);
361396
```
362397

363398
Instead, mixins should be assigned to variables, and variables should be interpolated in an escaped string like this:
364399

365-
```
400+
```scss
366401
@color1: fade(@color-pf-black, 7.5%);
367402
@color2: lighten(@state-danger-text, 20%);
368403
box-shadow: ~"inset 0 1px 1px @{color1}, 0 0 6px @{color2}";
@@ -386,13 +421,13 @@ The HTML pages in `dist/tests` are generated using Jekyll. Do *not* edit these
386421
### Unit Testing
387422
Unit tests are written for [Karma test server] (https://karma-runner.github.io/1.0/index.html) with [Jasmine](http://jasmine.github.io/)
388423

389-
```
424+
```sh
390425
npm test
391426
```
392427

393428
or
394429

395-
```
430+
```sh
396431
grunt karma
397432
```
398433
### Visual Regression Testing

0 commit comments

Comments
 (0)