【问题标题】:Grunt - start_server-watch-jshint-html_minify咕噜声 - start_server-watch-jshint-html_minify
【发布时间】:2021-07-28 05:20:19
【问题描述】:
编写一个 grunt 文件来验证 js
使用 jshint 文件,压缩 html 文件,启动 web 服务器并监视本地 web 服务器。
【问题讨论】:
标签:
gruntjs
grunt-contrib-watch
【解决方案1】:
为以下所有任务安装必要的 grunt 命令,并确保命令保存在 packages.json 中并尝试以下操作:
module.exports = function(grunt) {
require('jit-grunt')(grunt);
grunt.initConfig({
jshint: {
files: ['Gruntfile.js', 'src/**/*.js', 'test/**/*.js'],
options: {
globals: {
jQuery: true
}
}
},
htmlmin: { // Task
dist: { // Target
options: { // Target options
removeComments: true,
collapseWhitespace: true
},
files: { // Dictionary of files
'dest/src/form.html': 'src/form.html', // 'destination': 'source'
'dest/src/management.html': 'src/management.html'
}
}
},
watch: {
styles: {
files: ['less/**/*.less'], // which files to watch
tasks: ['less'],
options: {
nospawn: true
}
}
},
connect: {
server: {
options: {
port: 9000,
base: 'app',
keepalive: false
}
}
}
});
grunt.registerTask('default', ['htmlmin','jshint','connect','watch']);
};