Skip to content
This repository was archived by the owner on Mar 26, 2018. It is now read-only.

Commit e6c2fa5

Browse files
fix(build): use Usemin for all CSS.
1 parent dd6a0cb commit e6c2fa5

File tree

8 files changed

+105
-53
lines changed

8 files changed

+105
-53
lines changed

app/index.js

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -76,31 +76,21 @@ util.inherits(Generator, yeoman.generators.Base);
7676
Generator.prototype.askForBootstrap = function askForBootstrap() {
7777
var cb = this.async();
7878

79-
this.prompt({
79+
this.prompt([{
8080
type: 'confirm',
8181
name: 'bootstrap',
8282
message: 'Would you like to include Twitter Bootstrap?',
8383
default: true
84-
}, function (props) {
85-
this.bootstrap = props.bootstrap;
86-
87-
cb();
88-
}.bind(this));
89-
};
90-
91-
Generator.prototype.askForCompass = function askForCompass() {
92-
if (!this.bootstrap) {
93-
return;
94-
}
95-
96-
var cb = this.async();
97-
98-
this.prompt({
84+
}, {
9985
type: 'confirm',
10086
name: 'compassBootstrap',
101-
message: 'If so, would you like to use Twitter Bootstrap for Compass (as opposed to vanilla CSS)?',
102-
default: true
103-
}, function (props) {
87+
message: 'Would you like to use Twitter Bootstrap for Compass (as opposed to vanilla CSS)?',
88+
default: true,
89+
when: function (props) {
90+
return props.bootstrap;
91+
}
92+
}], function (props) {
93+
this.bootstrap = props.bootstrap;
10494
this.compassBootstrap = props.compassBootstrap;
10595

10696
cb();
@@ -138,16 +128,33 @@ Generator.prototype.askForModules = function askForModules() {
138128

139129
// Waiting a more flexible solution for #138
140130
Generator.prototype.bootstrapFiles = function bootstrapFiles() {
141-
if (this.compassBootstrap) {
142-
this.copy('styles/bootstrap.scss', path.join(this.appPath, 'styles/main.scss'));
143-
} else if (this.bootstrap) {
144-
this.log.writeln('Writing compiled Bootstrap');
145-
var cssFiles = ['styles/bootstrap.css', 'styles/main.css'];
146-
147-
cssFiles.forEach(function (css) {
148-
this.copy(css, path.join(this.appPath, css));
149-
}.bind(this));
131+
var sass = this.compassBootstrap;
132+
var files = [];
133+
var source = 'styles/' + ( sass ? 'scss/' : 'css/' );
134+
135+
if (sass) {
136+
files.push('main.scss');
137+
} else {
138+
if (this.bootstrap) {
139+
files.push('bootstrap.css');
140+
}
141+
142+
files.push('main.css');
150143
}
144+
145+
files.forEach(function (file) {
146+
this.copy(source + file, 'app/styles/' + file);
147+
}.bind(this));
148+
149+
this.indexFile = this.appendFiles({
150+
html: this.indexFile,
151+
fileType: 'css',
152+
optimizedPath: 'styles/main.css',
153+
sourceFileList: files.map(function (file) {
154+
return 'styles/' + file.replace('.scss', '.css');
155+
}),
156+
searchPath: ['.tmp', 'app']
157+
});
151158
};
152159

153160
Generator.prototype.bootstrapJS = function bootstrapJS() {
@@ -192,7 +199,6 @@ Generator.prototype.extraModules = function extraModules() {
192199
this.indexFile = this.appendScripts(this.indexFile, 'scripts/modules.js',
193200
modules);
194201
}
195-
196202
};
197203

198204
Generator.prototype.createIndexHtml = function createIndexHtml() {

app/templates/styles/bootstrap.scss

Lines changed: 0 additions & 6 deletions
This file was deleted.

app/templates/styles/css/main.css

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
body {
2+
background: #fafafa;
3+
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
4+
color: #333;
5+
}
6+
7+
.hero-unit {
8+
margin: 50px auto 0 auto;
9+
width: 300px;
10+
font-size: 18px;
11+
font-weight: 200;
12+
line-height: 30px;
13+
background-color: #eee;
14+
border-radius: 6px;
15+
padding: 60px;
16+
}
17+
18+
.hero-unit h1 {
19+
font-size: 60px;
20+
line-height: 1;
21+
letter-spacing: -1px;
22+
}

app/templates/styles/main.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

app/templates/styles/scss/main.scss

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
@import "bootstrap-sass/lib/bootstrap";
2+
3+
/* Put your CSS here */
4+
html, body {
5+
margin: 20px;
6+
}
7+
8+
body {
9+
background: #fafafa;
10+
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
11+
color: #333;
12+
}
13+
14+
.hero-unit {
15+
margin: 50px auto 0 auto;
16+
width: 300px;
17+
font-size: 18px;
18+
font-weight: 200;
19+
line-height: 30px;
20+
background-color: #eee;
21+
border-radius: 6px;
22+
padding: 60px;
23+
}
24+
25+
.hero-unit h1 {
26+
font-size: 60px;
27+
line-height: 1;
28+
letter-spacing: -1px;
29+
}

templates/common/Gruntfile.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,17 @@ module.exports = function (grunt) {
201201
}
202202
},
203203
cssmin: {
204-
dist: {
205-
files: {
206-
'<%%= yeoman.dist %>/styles/main.css': [
207-
'.tmp/styles/{,*/}*.css',
208-
'<%%= yeoman.app %>/styles/{,*/}*.css'
209-
]
210-
}
211-
}
204+
// By default, your `index.html` <!-- Usemin Block --> will take care of
205+
// minification. This option is pre-configured if you do not wish to use
206+
// Usemin blocks.
207+
// dist: {
208+
// files: {
209+
// '<%%= yeoman.dist %>/styles/main.css': [
210+
// '.tmp/styles/{,*/}*.css',
211+
// '<%%= yeoman.app %>/styles/{,*/}*.css'
212+
// ]
213+
// }
214+
// }
212215
},
213216
htmlmin: {
214217
dist: {
@@ -329,11 +332,11 @@ module.exports = function (grunt) {
329332
'clean:dist',
330333
'useminPrepare',
331334
'concurrent:dist',
332-
'cssmin',
333335
'concat',
334336
'copy',
335337
'cdnify',
336338
'ngmin',
339+
'cssmin',
337340
'uglify',
338341
'rev',
339342
'usemin'

templates/common/index.html

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
<meta name="description" content="">
1111
<meta name="viewport" content="width=device-width">
1212
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
13-
<link rel="stylesheet" href="styles/main.css">
1413
</head>
1514
<body ng-app="<%= _.camelize(appname) %>App">
1615
<!--[if lt IE 7]>
@@ -25,19 +24,19 @@
2524
<!-- Add your site or application content here -->
2625
<div class="container" ng-view></div>
2726

28-
<script src="bower_components/angular/angular.js"></script>
29-
30-
<!-- build:js scripts/scripts.js -->
31-
<script src="scripts/app.js"></script>
32-
<script src="scripts/controllers/main.js"></script>
33-
<!-- endbuild -->
34-
3527
<!-- Google Analytics: change UA-XXXXX-X to be your site's ID. -->
3628
<script>
3729
var _gaq=[['_setAccount','UA-XXXXX-X'],['_trackPageview']];
3830
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
3931
g.src='//www.google-analytics.com/ga.js';
4032
s.parentNode.insertBefore(g,s)}(document,'script'));
4133
</script>
34+
35+
<script src="bower_components/angular/angular.js"></script>
36+
37+
<!-- build:js scripts/scripts.js -->
38+
<script src="scripts/app.js"></script>
39+
<script src="scripts/controllers/main.js"></script>
40+
<!-- endbuild -->
4241
</body>
4342
</html>

0 commit comments

Comments
 (0)