下面是我的 Grunt 文件。我的watch:news
命令似乎不起作用,我不确定为什么。
当我在详细模式下运行时,我可以看到所有 NPM 模块都已加载而没有问题,并且它验证watch:news
任务是否按应有的方式运行,但它只是没有发现发生了任何更改?
我确定这可能是一个错字或一些小/易于修复的问题,我只是无法发现它?
非常感谢任何帮助!
module.exports = function (grunt) {
/*
Grunt installation:
-------------------
npm install -g grunt-cli
npm install -g grunt-init
npm init (creates a `package.json` file)
Project Dependencies:
---------------------
npm install grunt --save-dev
npm install grunt-contrib-watch --save-dev
npm install grunt-contrib-jshint --save-dev
npm install grunt-contrib-uglify --save-dev
npm install grunt-contrib-requirejs --save-dev
npm install grunt-contrib-sass --save-dev
npm install grunt-contrib-imagemin --save-dev
Example Usage:
--------------
grunt -v
grunt release -v
*/
// Project configuration.
grunt.initConfig({
// Store your Package file so you can reference its specific data whenever necessary
pkg: grunt.file.readJSON('package.json'),
dir: {
static: './tabloid/webapp/static/',
static_js: '<%= dir.static %>' + 'js/',
static_sass: '<%= dir.static %>' + 'sass/',
static_css: '<%= dir.static %>' + 'stylesheets/',
static_img: '<%= dir.static %>' + 'img/'
},
jshint: {
files: ['<%= dir.static %>**/*.js',
'!<%= dir.static_js %>jasmine/lib/**/*.js',
'!<%= dir.static_js %>build.js',
'!<%= dir.static_js %>compiled/**/*.js',
'!<%= dir.static_js %>locator/**/*.js',
'!<%= dir.static_js %>msie/**/*.js',
'!<%= dir.static_js %>vendor/**/*.js'],
options: {
curly: true,
eqeqeq: true,
immed: true,
latedef: true,
noarg: true,
sub: true,
undef: true,
boss: true,
eqnull: true,
browser: true,
multistr: true,
newcap: false,
globals: {
// AMD
module: true,
require: true,
requirejs: true,
define: true,
// Environments
console: true,
// General Purpose Libraries
$: true,
jQuery: true,
EventEmitter: true,
// Testing
sinon: true,
describe: true,
it: true,
expect: true,
beforeEach: true,
afterEach: true
}
}
},
requirejs: {
compile: {
options: {
baseUrl: '<%= dir.static_js %>',
paths: {
'jquery-1': 'vendor/jquery-1/jquery.min',
'jquery': 'vendor/jquery-2/jquery.min',
'domReady': 'vendor/require/domReady',
'translation': 'module/translations/news'
},
exclude: ['config', 'jquery' ],
name: 'define',
out: '<%= dir.static_js %>compiled/all.js',
fileExclusionRegExp: /^\.|node_modules|Gruntfile|\.md|package.json/
}
}
},
sass: {
dist: {
options: {
style: 'compressed',
require: ['<%= dir.static_sass %>helpers/url64.rb']
},
expand: true,
cwd: '<%= dir.static_sass %>',
src: ['*.scss', '!_*.scss'],
dest: '<%= dir.static_css %>',
ext: '.css'
},
dev: {
options: {
style: 'expanded',
debugInfo: true,
lineNumbers: true,
require: ['<%= dir.static_sass %>helpers/url64.rb']
},
expand: true,
cwd: '<%= dir.static_sass %>',
src: ['*.scss', '!_*.scss'],
dest: '<%= dir.static_css %>',
ext: '.css'
},
news: {
options: {
style: 'expanded',
debugInfo: true,
lineNumbers: true,
require: ['<%= dir.static_sass %>helpers/url64.rb']
},
expand: true,
cwd: '<%= dir.static_sass %>/services/news/',
src: ['*.scss'],
dest: '<%= dir.static_css %>/services/news/',
ext: '.css'
}
},
// `optimizationLevel` is only applied to PNG files (not JPG)
imagemin: {
png: {
options: {
optimizationLevel: 7
},
files: [
{
expand: true,
cwd: '<%= dir.static %>img/',
src: ['**/*.png'],
dest: '<%= dir.static %>img/',
ext: '.png'
}
]
},
jpg: {
options: {
progressive: true
},
files: [
{
expand: true,
cwd: '<%= dir.static %>img/',
src: ['**/*.jpg'],
dest: '<%= dir.static %>img/',
ext: '.jpg'
}
]
}
},
// Run: `grunt watch -v` from command line for this section to take effect
// The -v flag is for 'verbose' mode, this means you can see the Sass files being compiled along with other important information
watch: {
all: {
files: ['<%= jshint.files %>', '<%= sass.dev.src %>'],
tasks: ['default']
},
news: {
files: ['<%= sass.news.src %>'],
tasks: ['news']
}
}
});
// Load NPM Tasks
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-imagemin');
// Default Task
grunt.registerTask('default', ['jshint', 'sass:dev']);
// News Task
grunt.registerTask('news', ['sass:news']);
// Release Task
grunt.registerTask('release', ['jshint', 'requirejs', 'sass:dist', 'imagemin']);
};