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