-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
163 lines (151 loc) · 4.48 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
module.exports = function (grunt) {
require('load-grunt-tasks')(grunt);
require('time-grunt')(grunt);
var appConfig = {
app: 'd1',
port: '3003',
dist: 'dist'
};
var bs;
grunt.initConfig({
appConfig: appConfig,
pkg: grunt.file.readJSON('package.json'),
// 开启同步服务
browserSync: {
dev: {
bsFiles: {
src: [
'Gruntfile.js',
'./<%= appConfig.app %>/{,*/}*.ejs',
'./<%= appConfig.app %>/{,*/}*.html',
'./<%= appConfig.app %>/{,*/}*.css',
'./<%= appConfig.app %>/{,*/}*.js'
]
},
options: {
proxy: 'localhost:3000',
//server: {
// baseDir: "./<%= appConfig.app %>/",
// // 将bower的路径改为相对于项目的路径
// routes: {
// "/bower_components": "bower_components"
// }
//},
// 开启实时监控
watchTask: true // < VERY important
}
}
},
// 实时监控文件变化
watch: {
comp: {
files: '<%= appConfig.app %>/public/scss/{,*/}*.scss',
tasks: ['compass']
}
},
compass: {
dist: {
options: {
config: 'config.rb'
}
}
},
concurrent: {
target: {
tasks: ['watch', 'nodemon'],
options: {
logConcurrentOutput: true
}
}
},
typescript: {
base: {
src: '<%= appConfig.app %>/public/typescript/{,*/}*.ts',
dest: '<%= appConfig.app %>/public/js',
options: {
//module: 'amd',
//target: 'es6',
rootDir: '<%= appConfig.app %>/public/typescript/',
sourceMap: true//,
//watch: true //Detect all target files root. eg: 'path/to/typescript/files/'
}
}
},
wiredep: {
task: {
// Point to the files that should be updated when
// you run `grunt wiredep`
src: [
'<%= appConfig.app %>/views/{,*/}*.html'//, // .html support...
//'app/views/**/*.jade', // .jade support...
//'app/styles/main.scss', // .scss & .sass support...
//'app/config.yml' // and .yml & .yaml support out of the box!
],
options: {
// See wiredep's configuration documentation for the options
// you may pass:
// https://github.com/taptapship/wiredep#configuration
}
}
},
nodemon: {
dev: {
script: '<%= appConfig.app %>/bin/www',
options: {
watch: ['<%= appConfig.app %>'],
ext: 'html, js, css',
env: {
PORT: appConfig.port
},
ignore: ['node_modules/**'],
// omit this property if you aren't serving HTML files and
// don't want to open a browser tab on start
callback: function (nodemon) {
nodemon.on('log', function (event) {
console.log(event.colour);
});
// opens browser on initial server start
nodemon.on('config:update', function () {
// Delay before server listens on port
//console.log('config update');
});
// refreshes browser when server reboots
nodemon.on('restart', function () {
// Delay before server listens on port
console.log('nodemon restart');
bs.reload();
});
nodemon.on('start', function () {
// Delay before server listens on port
console.log('nodemon start');
//browserSync.reload();
if (!bs) {
console.log('create bs');
bs = require("browser-sync").create();
bs.init({
proxy: {
target: 'localhost:' + appConfig.port
}
//port: 3000,
//server: {
// baseDir: appConfig.app
//},
//open: 'localhost'
});
bs.watch([
appConfig.app + '/**/*.html',
appConfig.app + '/**/*.ejs',
appConfig.app + '/**/*.js',
appConfig.app + '/**/*.css'
]).on('change', function () {
console.log('*----change----*');
nodemon.restart();
});
}
});
}
}
}
}
});
};