|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 |
| -module.exports = function(grunt) { |
4 |
| - // Add require for connect-modewrite |
5 |
| - var modRewrite = require('connect-modrewrite'); |
| 3 | +module.exports = function (grunt) { |
| 4 | + // Add require for connect-modewrite |
| 5 | + var modRewrite = require('connect-modrewrite'); |
6 | 6 |
|
7 |
| - // Define the configuration for all the tasks |
8 |
| - grunt.initConfig({ |
9 |
| - // Project settings |
10 |
| - bowerApp: { |
11 |
| - // configurable app path |
12 |
| - app: require('./bower.json').appPath || 'app' |
13 |
| - }, |
| 7 | + // Define the configuration for all the tasks |
| 8 | + grunt.initConfig({ |
| 9 | + // Project settings |
| 10 | + app: './app', |
| 11 | + demo: './docs', |
14 | 12 |
|
15 |
| - // Watches files for changes and runs tasks based on the changed files |
16 |
| - watch: { |
17 |
| - bower: { |
18 |
| - files: ['bower.json'], |
19 |
| - tasks: ['bowerInstall'] |
20 |
| - }, |
21 |
| - js: { |
22 |
| - files: ['<%= bowerApp.app %>/js/{,*/}*.js', '<%= bowerApp.app %>/demo/{,*/}*.js'], |
| 13 | + // Watches files for changes and runs tasks based on the changed files |
| 14 | + watch: { |
| 15 | + js: { |
| 16 | + files: ['<%= app %>/js/{,*/}*.js', '<%= demo %>/{,*/}*.js'], |
23 | 17 |
|
24 |
| - options: { |
25 |
| - livereload: true |
26 |
| - } |
27 |
| - }, |
28 |
| - styles: { |
29 |
| - files: ['<%= bowerApp.app %>/css/{,*/}*.css'], |
30 |
| - options: { |
31 |
| - livereload: true |
32 |
| - } |
33 |
| - }, |
34 |
| - gruntfile: { |
35 |
| - files: ['Gruntfile.js'] |
36 |
| - }, |
37 |
| - livereload: { |
38 |
| - options: { |
39 |
| - livereload: '<%= connect.options.livereload %>' |
40 |
| - }, |
41 |
| - files: [ |
42 |
| - '<%= bowerApp.app %>/{,*/}*.html', |
43 |
| - '<%= bowerApp.app %>/img/{,*/}*.{png,jpg,jpeg,gif,webp,svg}' |
44 |
| - ] |
45 |
| - } |
| 18 | + options: { |
| 19 | + livereload: true |
| 20 | + } |
| 21 | + }, |
| 22 | + styles: { |
| 23 | + files: ['<%= app %>/css/{,*/}*.css'], |
| 24 | + options: { |
| 25 | + livereload: true |
| 26 | + } |
| 27 | + }, |
| 28 | + gruntfile: { |
| 29 | + files: ['Gruntfile.js'] |
| 30 | + }, |
| 31 | + livereload: { |
| 32 | + options: { |
| 33 | + livereload: '<%= connect.options.livereload %>' |
46 | 34 | },
|
47 |
| - // The actual grunt server settings |
48 |
| - connect: { |
49 |
| - options: { |
50 |
| - port: 9000, |
51 |
| - // Change this to '0.0.0.0' to access the server from outside. |
52 |
| - hostname: 'localhost', |
53 |
| - livereload: 35729, |
54 |
| - base: [ |
55 |
| - '<%= bowerApp.app %>', |
56 |
| - '<%= bowerApp.app %>/demo/'] |
| 35 | + files: [ |
| 36 | + '<%= app %>/{,*/}*.html', |
| 37 | + '<%= app %>/img/{,*/}*.{png,jpg,jpeg,gif,webp,svg}' |
| 38 | + ] |
| 39 | + } |
| 40 | + }, |
| 41 | + // The actual grunt server settings |
| 42 | + connect: { |
| 43 | + options: { |
| 44 | + port: 9000, |
| 45 | + // Change this to '0.0.0.0' to access the server from outside. |
| 46 | + hostname: 'localhost', |
| 47 | + livereload: 35729, |
| 48 | + base: ['./dist', |
| 49 | + '<%= app %>', |
| 50 | + '<%= demo %>'] |
57 | 51 |
|
58 |
| - }, |
59 |
| - livereload: { |
60 |
| - options: { |
61 |
| - open: 'http://localhost:<%= connect.options.port %>', |
62 |
| - base: [ |
63 |
| - '.tmp', |
64 |
| - '<%= bowerApp.app %>', |
65 |
| - '<%= bowerApp.app %>/demo/' |
66 |
| - ], |
67 |
| - // MODIFIED: Add this middleware configuration |
68 |
| - middleware: function(connect, options) { |
69 |
| - var middlewares = []; |
| 52 | + }, |
| 53 | + livereload: { |
| 54 | + options: { |
| 55 | + open: 'http://localhost:<%= connect.options.port %>', |
| 56 | + base: [ |
| 57 | + '.tmp', |
| 58 | + '<%= app %>', |
| 59 | + '<%= demo %>' |
| 60 | + ], |
| 61 | + // MODIFIED: Add this middleware configuration |
| 62 | + middleware: function (connect, options) { |
| 63 | + var middlewares = []; |
70 | 64 |
|
71 |
| - middlewares.push(modRewrite(['^[^\\.]*$ /index.html [L]'])); //Matches everything that does not contain a '.' (period) |
72 |
| - options.base.forEach(function(base) { |
73 |
| - middlewares.push(connect.static(base)); |
74 |
| - }); |
75 |
| - return middlewares; |
76 |
| - } |
77 |
| - } |
78 |
| - } |
| 65 | + middlewares.push(modRewrite(['^[^\\.]*$ /index.html [L]'])); //Matches everything that does not contain a '.' (period) |
| 66 | + options.base.forEach(function (base) { |
| 67 | + middlewares.push(connect.static(base)); |
| 68 | + }); |
| 69 | + return middlewares; |
| 70 | + } |
| 71 | + } |
| 72 | + } |
79 | 73 |
|
80 |
| - }, |
81 |
| - concat: { |
82 |
| - dist: { |
83 |
| - src: ['<%= bowerApp.app %>/js/**/*.js'], |
84 |
| - dest: 'dist/ruler.js' |
85 |
| - } |
86 |
| - }, |
87 |
| - cssmin: { |
88 |
| - dist: { |
89 |
| - files: [{ |
90 |
| - expand: true, |
91 |
| - cwd: '<%= bowerApp.app %>/css/', |
92 |
| - src: ['*.css', '!*.min.css'], |
93 |
| - dest: 'dist', |
94 |
| - ext: '.min.css' |
95 |
| - }] |
96 |
| - } |
97 |
| - }, |
98 |
| - uglify: { |
99 |
| - dist: { |
100 |
| - files: { |
101 |
| - 'dist/ruler.min.js': ['<%= bowerApp.app %>/js/ruler.js'] |
102 |
| - } |
103 |
| - } |
| 74 | + }, |
| 75 | + concat: { |
| 76 | + dist: { |
| 77 | + src: ['<%= app %>/js/**/*.js'], |
| 78 | + dest: 'dist/ruler.js' |
| 79 | + } |
| 80 | + }, |
| 81 | + cssmin: { |
| 82 | + dist: { |
| 83 | + files: [{ |
| 84 | + expand: true, |
| 85 | + cwd: '<%= app %>/css/', |
| 86 | + src: ['*.css', '!*.min.css'], |
| 87 | + dest: 'dist', |
| 88 | + ext: '.min.css' |
| 89 | + }] |
| 90 | + } |
| 91 | + }, |
| 92 | + uglify: { |
| 93 | + dist: { |
| 94 | + files: { |
| 95 | + 'dist/ruler.min.js': ['dist/ruler.js'] |
104 | 96 | }
|
105 |
| - }); |
106 |
| - // Load tasks |
107 |
| - grunt.loadNpmTasks('grunt-contrib-connect'); |
108 |
| - grunt.loadNpmTasks('grunt-bower-install'); |
109 |
| - grunt.loadNpmTasks('grunt-express'); |
110 |
| - grunt.loadNpmTasks('grunt-shell'); |
111 |
| - grunt.loadNpmTasks('grunt-contrib-concat'); |
112 |
| - grunt.loadNpmTasks('grunt-contrib-cssmin'); |
113 |
| - grunt.loadNpmTasks('grunt-contrib-uglify'); |
| 97 | + } |
| 98 | + }, |
| 99 | + copy: { |
| 100 | + main: { |
| 101 | + files: [ |
| 102 | + // includes files within path |
| 103 | + {expand: true, src: ['./dist/*'], dest: '<%= demo %>', filter: 'isFile'}, |
| 104 | + ] |
| 105 | + } |
| 106 | + } |
| 107 | + }); |
| 108 | + // Load tasks |
| 109 | + grunt.loadNpmTasks('grunt-contrib-connect'); |
| 110 | + grunt.loadNpmTasks('grunt-bower-install'); |
| 111 | + grunt.loadNpmTasks('grunt-express'); |
| 112 | + grunt.loadNpmTasks('grunt-shell'); |
| 113 | + grunt.loadNpmTasks('grunt-contrib-concat'); |
| 114 | + grunt.loadNpmTasks('grunt-contrib-cssmin'); |
| 115 | + grunt.loadNpmTasks('grunt-contrib-copy'); |
| 116 | + grunt.loadNpmTasks('grunt-contrib-uglify'); |
114 | 117 |
|
115 | 118 |
|
116 |
| - grunt.registerTask('build', [ |
117 |
| - 'concat', |
118 |
| - 'cssmin', |
119 |
| - 'uglify' |
120 |
| - ]); |
| 119 | + grunt.registerTask('build', [ |
| 120 | + 'concat', |
| 121 | + 'cssmin', |
| 122 | + 'uglify', |
| 123 | + 'copy' |
| 124 | + ]); |
121 | 125 |
|
122 |
| - // Register new tasks |
123 |
| - grunt.registerTask('serve', ['connect', 'watch']); |
| 126 | + // Register new tasks |
| 127 | + grunt.registerTask('serve', ['build', 'connect', 'watch']); |
124 | 128 | }
|
0 commit comments