Skip to content

Commit

Permalink
Support grunt-contrib-copy + uglify tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
nomospace committed Nov 28, 2015
1 parent 6d569f0 commit c9051b3
Show file tree
Hide file tree
Showing 14 changed files with 291 additions and 191 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,3 +4,4 @@ src/bower_components
src/assets/styles/all.css
dist
node_modules
temp
4 changes: 3 additions & 1 deletion .jshintrc
Expand Up @@ -28,6 +28,8 @@
"exports": true,
"define": true,
"module": true,
"require": true
"require": true,
"$": true,
"jQuery": true
}
}
91 changes: 69 additions & 22 deletions Gruntfile.js
Expand Up @@ -4,6 +4,8 @@ module.exports = function(grunt) {
grunt.initConfig({
port: 5601,
liveReloadPort: 35729,
srcDir: "src",
tempDir: "temp",
// Import package manifest
pkg: grunt.file.readJSON("package.json"),

Expand All @@ -19,39 +21,62 @@ module.exports = function(grunt) {
" */\n"
},

// Clean the project
clean: {
temp: ["<%=tempDir%>"]
},

// Copy files
copy: {
src: {
cwd: "<%=srcDir%>",
expand: true,
src: ["**/*", "!assets/**/*.{less,css}", "!*/*.hbs"],
dest: "<%=tempDir%>"
}
},

// Compile less
less: {
compile: {
files: {
"src/assets/styles/all.css": "src/assets/styles/**/*.less"
"<%=tempDir%>/assets/styles/all.css": "<%=srcDir%>/assets/styles/**/*.less"
//expand: true,
//cwd: "<%=srcDir%>/assets/styles/",
//src: ["**/*.less"],
//dest: "<%=tempDir%>/assets/styles/",
//ext: ".css",
//extDot: "last"
}
},
compress: {
options: {
compress: true
},
files: "src/assets/styles/all.css"
files: "<%=tempDir%>/assets/styles/all.css"
}
},

// Concat definitions
concat: {
js: {
options: {
banner: "<%= meta.banner %>"
banner: "<%=meta.banner%>"
},
files: {
src: ["src/app/*.js"],
dest: "dist/app.js"
"<%=tempDir%>/*.js": ["<%=tempDir%>/assets/scripts/**/*.js", "<%=tempDir%>/app.js"]
}
},
css: {
options: {
banner: "<%= meta.banner %>",
banner: "<%=meta.banner%>",
separator: ""
},
files: {
"src/assets/styles/all.css": ["src/assets/styles/all.css", "src/assets/styles/vendor/*.css"]
"<%=tempDir%>/assets/styles/all.css": [
"<%=tempDir%>/assets/styles/all.css",
"<%=srcDir%>/assets/styles/vendor/*.css"
]
}
}
},
Expand All @@ -60,7 +85,7 @@ module.exports = function(grunt) {
jshint: {
files: [
"Gruntfile.js",
"src/assets/**/*.js"
"./<%=srcDir%>/assets/**/*.js"
],
options: {
jshintrc: ".jshintrc"
Expand All @@ -71,10 +96,10 @@ module.exports = function(grunt) {
uglify: {
js: {
options: {
banner: "<%= meta.banner %>"
banner: "<%=meta.banner%>"
},
files: {
"dist/app.js": ["src/assets/scripts/**/*.js"]
"<%=tempDir%>/app.js": "<%=tempDir%>/app.js"
}
}
},
Expand All @@ -86,30 +111,51 @@ module.exports = function(grunt) {
},
compress: {
files: {
"src/assets/styles/all.css": "src/assets/styles/all.css"
"<%=tempDir%>/assets/styles/all.css": "<%=tempDir%>/assets/styles/all.css"
}
}
},

handlebars: {
compile: {
options: {
namespace: false,
amd: true,
processContent: function(content) {
content = content.replace(/^[\x20\t]+/mg, "").replace(/[\x20\t]+$/mg, "");
content = content.replace(/^[\r\n]+/, "").replace(/[\r\n]+$/, "");
return content;
}
},
files: {
"<%=tempDir%>/templates/link-item.js": ["<%=srcDir%>/templates/link-item.hbs"],
"<%=tempDir%>/templates/link-item-recent.js": ["<%=srcDir%>/templates/link-item-recent.hbs"]
}
}
},
// watch for changes to source
// Better than calling grunt a million times
watch: {
js: {
files: ["src/**/*.js"],
files: ["<%=srcDir%>/**/*.js"],
tasks: ["jshint"]
},
css: {
files: ["src/**/*.{less,css}"],
files: ["<%=srcDir%>/**/*.{less,css}"],
tasks: ["less", "concat:css"]
},
hbs: {
files: ["<%=srcDir%>/templates/*.hbs"],
tasks: ["handlebars"]
},
options: {
livereload: "<%=liveReloadPort%>"
}
},

open: {
server: {
path: 'http://localhost:<%=port%>/'
path: "http://localhost:<%=port%>/"
}
},

Expand All @@ -118,12 +164,8 @@ module.exports = function(grunt) {
options: {
port: "<%=port%>",
livereload: true,
middleware: function() {
return [
require('serve-static')("src"),
require("connect-livereload")({port: "<%=liveReloadPort%>"})
];
}
base: ["<%=tempDir%>"],
middleware: null
}
}
}
Expand All @@ -132,15 +174,20 @@ module.exports = function(grunt) {

grunt.loadNpmTasks("grunt-contrib-concat");
grunt.loadNpmTasks("grunt-contrib-jshint");
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks("grunt-contrib-less");
grunt.loadNpmTasks("grunt-contrib-cssmin");
grunt.loadNpmTasks("grunt-contrib-handlebars");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks("grunt-contrib-connect");
grunt.loadNpmTasks("grunt-open");

grunt.registerTask("build", ["less", "concat:css", "uglify", "cssmin"/*, "uglify:js"*/]);
grunt.registerTask("build", ["clean", "copy:src", "less", "concat:css", "handlebars"]);
grunt.registerTask("default", ["jshint", "build", "connect:dev", "open", "watch"]);
grunt.registerTask("release", ["default", "uglify", "cssmin", "connect:dev", "open", "watch"]);
grunt.registerTask("serve", ["default"]);
grunt.registerTask("travis", ["default"]);

};
5 changes: 2 additions & 3 deletions README.md
Expand Up @@ -8,8 +8,8 @@

# Run

grunt serve // development
grunt serve:dist // production
grunt serve // development
grunt release // production

# Build

Expand All @@ -21,6 +21,5 @@

# Build war

grunt release

# Documentation
3 changes: 2 additions & 1 deletion bower.json
Expand Up @@ -21,7 +21,8 @@
"underscore": "~1.8.3",
"moment": "~2.10.6",
"requirejs-text": "~2.0.14",
"fontawesome": "~4.5.0"
"fontawesome": "~4.5.0",
"handlebars": "~4.0.5"
},
"devDependencies": {}
}
7 changes: 6 additions & 1 deletion package.json
Expand Up @@ -15,13 +15,18 @@
"dependencies": {
"grunt": "~0.4.5",
"grunt-cli": "~0.1.13",
"grunt-contrib-clean": "^0.7.0",
"grunt-contrib-concat": "^0.5.1",
"grunt-contrib-connect": "^0.11.2",
"grunt-contrib-copy": "^0.8.2",
"grunt-contrib-cssmin": "^0.14.0",
"grunt-contrib-handlebars": "^0.11.0",
"grunt-contrib-jshint": "^0.11.0",
"grunt-contrib-less": "^1.1.0",
"grunt-contrib-uglify": "^0.8.0",
"grunt-contrib-watch": "^0.6.1",
"grunt-open": "^0.2.3",
"grunt-contrib-connect": "^0.11.2",
"lodash": "^3.10.1",
"serve-static": "^1.10.0"
},
"devDependencies": {
Expand Down
11 changes: 9 additions & 2 deletions src/app.js
@@ -1,4 +1,11 @@
define(["b", "c"], function(b, c) {
define(["handlebars", "../../templates/link-item", "../../templates/link-item-recent"], function(hb, linkItemTemplate, linkItemRecentTemplate) {
"use strict";
console.log(b, c);
var $ = jQuery,
$linkListContainer = $("#link_list"),
$linkListRecentContainer = $("#link_list_recent");
console.log(hb);
$.getJSON("mock/links.json").done(function(result) {
$linkListContainer.html(linkItemTemplate(result));
$linkListRecentContainer.html(linkItemRecentTemplate(result));
});
});
11 changes: 8 additions & 3 deletions src/assets/scripts/require.config.js
Expand Up @@ -10,6 +10,8 @@
lodash: "../../bower_components/underscore/underscore",
bootstrap: "../../bower_components/bootstrap/dist/js/bootstrap",
jquery: "../../bower_components/jquery/dist/jquery",
handlebars: "../../bower_components/handlebars/handlebars.runtime",
//template: "../../templates/all",
text: "../../bower_components/requirejs-text/text"
},
shim: {
Expand All @@ -18,12 +20,15 @@
},
bootstrap: {
deps: ["jquery"]
//},
//template: {
// deps: ["handlebars"]
}
},
callback: function() {
require(["bootstrap", function() {
require("../../app");
}]);
require(["bootstrap"], function() {
require(["../../app"]);
});
}
});
}.call(this));
6 changes: 6 additions & 0 deletions src/assets/styles/common.less
Expand Up @@ -35,7 +35,13 @@ ol, ul {
}
}
}
}
}

.footer {
text-align: center;
&.well {
margin-bottom: 0;
}
}

6 changes: 5 additions & 1 deletion src/assets/styles/link-list.less
Expand Up @@ -44,11 +44,15 @@
}
.link-tags {
float: right;
li {
display: inline;
margin-right: 10px;
}
}
.link-meta {
font-size: 12px;
li {
float: left;
display: inline;
margin-right: 20px;
a {
color: #aea79f;
Expand Down

0 comments on commit c9051b3

Please sign in to comment.