Skip to content

Commit bbd9a14

Browse files
committed
docs: css preprocessors support
1 parent ef5ae91 commit bbd9a14

File tree

6 files changed

+43
-95
lines changed

6 files changed

+43
-95
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ The generated project has dependencies that require **Node 4 or greater**.
3333
* [Deploying the App via GitHub Pages](#deploying-the-app-via-github-pages)
3434
* [Support for offline applications](#support-for-offline-applications)
3535
* [Commands autocompletion](#commands-autocompletion)
36+
* [CSS preprocessor integration](#css-preprocessor-integration)
3637
* [Known Issues](#known-issues)
3738

3839
## Installation
@@ -249,6 +250,18 @@ ng completion >> ~/.bash_profile
249250
source ~/.bash_profile
250251
```
251252

253+
254+
### CSS Preprocessor integration
255+
256+
We support all major CSS preprocessors:
257+
- sass (node-sass)
258+
- less (less)
259+
- compass (compass-importer + node-sass)
260+
- stylus (stylus)
261+
262+
To use one just install for example `npm install node-sass` and rename `.css` files in your project to `.scss` or `.sass`. They will be compiled automatically.
263+
264+
252265
## Known issues
253266

254267
This project is currently a prototype so there are many known issues. Just to mention a few:

lib/broccoli/angular-broccoli-compass.js

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,8 @@
22
'use strict';
33

44
try {
5-
let sass;
6-
let compass;
7-
8-
if (process.platform === 'win32') {
9-
require.resolve(`${process.env.PWD}/node_modules/node-sass`);
10-
require.resolve(`${process.env.PWD}/node_modules/compass-importer`);
11-
sass = require(`${process.env.PWD}/node_modules/node-sass`);
12-
compass = require(`${process.env.PWD}/node_modules/compass-importer`);
13-
} else {
14-
process.env.NODE_PATH += `:${process.env.PWD}/node_modules`;
15-
require('module').Module._initPaths();
16-
require.resolve('node-sass');
17-
require.resolve('compass-importer');
18-
sass = require('node-sass');
19-
compass = require('compass-importer');
20-
}
21-
5+
const sass = require(`${process.env.PWD}/node_modules/node-sass`);
6+
const compass = require(`${process.env.PWD}/node_modules/compass-importer`);
227
const Plugin = require('broccoli-caching-writer');
238
const fse = require('fs-extra');
249
const path = require('path');
@@ -37,28 +22,22 @@ try {
3722
}
3823

3924
build() {
40-
let entries = this.listEntries();
41-
let rootFileNames = entries.map(e => {
42-
return path.resolve(e.basePath, e.relativePath);
43-
});
44-
45-
rootFileNames.forEach(fileName => {
25+
this.listEntries().forEach(e => {
26+
let fileName = path.resolve(e.basePath, e.relativePath);
4627
this.compile(fileName, this.inputPaths[0], this.outputPath);
4728
});
4829
}
4930

5031
compile(fileName, inputPath, outputPath) {
5132
let sassOptions = {
52-
file: path.join(fileName),
33+
file: path.normalize(fileName),
5334
includePaths: this.inputPaths,
5435
data: '@import "compass"; .transition { @include transition(all); }',
5536
importer: compass
5637
};
5738

5839
let result = sass.renderSync(sassOptions);
59-
let filePath = fileName.replace(inputPath, outputPath)
60-
.replace(/\.scss$/, '.css')
61-
.replace(/\.sass$/, '.css');
40+
let filePath = fileName.replace(inputPath, outputPath).replace(/\.s[ac]ss$/, '.css');
6241

6342
fse.outputFileSync(filePath, result.css, 'utf8');
6443
}

lib/broccoli/angular-broccoli-less.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,7 @@
22
'use strict';
33

44
try {
5-
let less;
6-
7-
if (process.platform === 'win32') {
8-
require.resolve(`${process.env.PWD}/node_modules/less`);
9-
less = require(`${process.env.PWD}/node_modules/less`);
10-
} else {
11-
process.env.NODE_PATH += `:${process.env.PWD}/node_modules`;
12-
require('module').Module._initPaths();
13-
require.resolve('less');
14-
less = require('less');
15-
}
16-
5+
const less = require(`${process.env.PWD}/node_modules/less`);
176
const Plugin = require('broccoli-caching-writer');
187
const fs = require('fs');
198
const fse = require('fs-extra');
@@ -33,12 +22,8 @@ try {
3322
}
3423

3524
build() {
36-
let entries = this.listEntries();
37-
let rootFileNames = entries.map(e => {
38-
return path.resolve(e.basePath, e.relativePath);
39-
});
40-
41-
return Promise.all(rootFileNames.map(fileName => {
25+
return Promise.all(this.listEntries().map(e => {
26+
let fileName = path.resolve(e.basePath, e.relativePath);
4227
return this.compile(fileName, this.inputPaths[0], this.outputPath);
4328
}));
4429
}

lib/broccoli/angular-broccoli-sass.js

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,7 @@
22
'use strict';
33

44
try {
5-
let sass;
6-
7-
if (process.platform === 'win32') {
8-
require.resolve(`${process.env.PWD}/node_modules/node-sass`);
9-
sass = require(`${process.env.PWD}/node_modules/node-sass`);
10-
} else {
11-
process.env.NODE_PATH += `:${process.env.PWD}/node_modules`;
12-
require('module').Module._initPaths();
13-
require.resolve('node-sass');
14-
sass = require('node-sass');
15-
}
16-
5+
const sass = require(`${process.env.PWD}/node_modules/node-sass`);
176
const Plugin = require('broccoli-caching-writer');
187
const fse = require('fs-extra');
198
const path = require('path');
@@ -32,12 +21,8 @@ try {
3221
}
3322

3423
build() {
35-
let entries = this.listEntries();
36-
let rootFileNames = entries.map(e => {
37-
return path.resolve(e.basePath, e.relativePath);
38-
});
39-
40-
rootFileNames.forEach(fileName => {
24+
this.listEntries().forEach(e => {
25+
let fileName = path.resolve(e.basePath, e.relativePath);
4126
this.compile(fileName, this.inputPaths[0], this.outputPath);
4227
});
4328
}
@@ -49,9 +34,7 @@ try {
4934
};
5035

5136
let result = sass.renderSync(sassOptions);
52-
let filePath = fileName.replace(inputPath, outputPath)
53-
.replace(/\.scss$/, '.css')
54-
.replace(/\.sass$/, '.css');
37+
let filePath = fileName.replace(inputPath, outputPath).replace(/\.s[ac]ss$/, '.css');
5538

5639
fse.outputFileSync(filePath, result.css, 'utf8');
5740
}

lib/broccoli/angular-broccoli-stylus.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,7 @@
22
'use strict';
33

44
try {
5-
let stylus;
6-
7-
if (process.platform === 'win32') {
8-
require.resolve(`${process.env.PWD}/node_modules/stylus`);
9-
stylus = require(`${process.env.PWD}/node_modules/stylus`);
10-
} else {
11-
process.env.NODE_PATH += `:${process.env.PWD}/node_modules`;
12-
require('module').Module._initPaths();
13-
require.resolve('stylus');
14-
stylus = require('stylus');
15-
}
16-
5+
const stylus = require(`${process.env.PWD}/node_modules/stylus`);
176
const Plugin = require('broccoli-caching-writer');
187
const fs = require('fs');
198
const fse = require('fs-extra');
@@ -33,12 +22,8 @@ try {
3322
}
3423

3524
build() {
36-
let entries = this.listEntries();
37-
let rootFileNames = entries.map(e => {
38-
return path.resolve(e.basePath, e.relativePath);
39-
});
40-
41-
return Promise.all(rootFileNames.map(fileName => {
25+
return Promise.all(this.listEntries().map(e => {
26+
let fileName = path.resolve(e.basePath, e.relativePath);
4227
return this.compile(fileName, this.inputPaths[0], this.outputPath);
4328
}));
4429
}

tests/e2e/e2e_workflow.spec.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ describe('Basic end-to-end Workflow', function () {
192192
});
193193
});
194194

195-
it('Installs sass support successfully via `ng install sass`', function() {
195+
it('Installs sass support successfully', function() {
196196
this.timeout(420000);
197197

198198
sh.exec('npm install node-sass', { silent: true });
@@ -217,11 +217,12 @@ describe('Basic end-to-end Workflow', function () {
217217
});
218218
});
219219

220-
it('Uninstalls sass support successfully via `ng uninstall sass`', function(done) {
220+
it('Uninstalls sass support successfully', function(done) {
221221
this.timeout(420000);
222222

223-
sh.exec('npm uninstall node-sass', { silent: true });
224223
let sassPath = path.join(process.cwd(), 'node_modules', 'node-sass');
224+
expect(existsSync(sassPath)).to.be.equal(true);
225+
sh.exec('npm uninstall node-sass', { silent: true });
225226
expect(existsSync(sassPath)).to.be.equal(false);
226227
return ng(['destroy', 'component', 'test-component'])
227228
.then(() => {
@@ -230,7 +231,7 @@ describe('Basic end-to-end Workflow', function () {
230231
});
231232
});
232233

233-
it('Installs less support successfully via `ng install less`', function() {
234+
it('Installs less support successfully', function() {
234235
this.timeout(420000);
235236

236237
sh.exec('npm install less', { silent: true });
@@ -255,19 +256,20 @@ describe('Basic end-to-end Workflow', function () {
255256
});
256257
});
257258

258-
it('Uninstalls less support successfully via `ng uninstall less`', function() {
259+
it('Uninstalls less support successfully', function() {
259260
this.timeout(420000);
260-
261-
sh.exec('npm uninstall less', { silent: true });
261+
262262
let lessPath = path.join(process.cwd(), 'node_modules', 'less');
263+
expect(existsSync(lessPath)).to.be.equal(true);
264+
sh.exec('npm uninstall less', { silent: true });
263265
expect(existsSync(lessPath)).to.be.equal(false);
264266
return ng(['destroy', 'component', 'test-component'])
265267
.then(() => {
266268
sh.rm('-rf', path.join(process.cwd(), 'src', 'app', 'test-component'));
267269
});
268270
});
269271

270-
it('Installs stylus support successfully via `ng install stylus`', function() {
272+
it('Installs stylus support successfully', function() {
271273
this.timeout(420000);
272274

273275
sh.exec('npm install stylus', { silent: true });
@@ -291,11 +293,12 @@ describe('Basic end-to-end Workflow', function () {
291293
});
292294
});
293295

294-
it('Uninstalls stylus support successfully via `ng uninstall stylus`', function() {
296+
it('Uninstalls stylus support successfully', function() {
295297
this.timeout(420000);
296-
297-
sh.exec('npm uninstall stylus', { silent: true });
298+
298299
let stylusPath = path.join(process.cwd(), 'node_modules', 'stylus');
300+
expect(existsSync(stylusPath)).to.be.equal(true);
301+
sh.exec('npm uninstall stylus', { silent: true });
299302
expect(existsSync(stylusPath)).to.be.equal(false);
300303
return ng(['destroy', 'component', 'test-component'])
301304
.then(() => {

0 commit comments

Comments
 (0)