- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
一段时间以来,我一直在尝试以特定方式组合两个 Grunt JS 插件。基本上,我想使用 UglifyJS 缩小目录中的所有 JS 文件。在此之后,我想使用版本控制插件(在本例中为 grunt-static-versioning)来实现缓存清除。
我的grunt文件如下:
module.exports = function(grunt) {
grunt.initConfig({
clean: ['dest/js'],
uglify: {
options: {
report: 'min',
mangle: true
},
my_target: {
files: [{
expand: true,
cwd: 'src/js',
src: '**/*.js',
dest: 'dest/js'
}]
}
},
cssmin: {
options: {
report:'min'
},
minify: {
expand:true,
cwd: 'src/css',
src: '**/*.css',
dest: 'dest/css',
}
},
imagemin: {
dynamic: {
options: {
optimizationLevel: 7
},
files: [{
expand:true,
cwd: 'src/assets',
src: ['**/*.{png,jpg,gif}'],
dest: 'dest/assets'
}]
}
},
htmlmin: {
mini :{
options: {
removeComments: true,
collapseWhitespace: true,
collapseBooleanAttributes: true,
removeAttributeQuotes: true,
removeRedundantAttributes: true,
removeEmptyAttributes: true,
useShortDoctype: true
},
files: [{
expand:true,
cwd: 'src',
src: '**/*.html',
dest: 'dest'
}]
}
},
versioning: { // Task
options: { // Task options
cwd: ''
},
dist: { // Target
options: { // Target options
},
files: [{
assets: '<%= uglify.my_target.files %>',
key: 'global',
dest: 'dest/js',
type: 'js',
ext: '.js'
}]
}
}
});
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-static-versioning');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-contrib-htmlmin');
grunt.registerTask('default', ['clean', 'uglify', 'cssmin', 'imagemin', 'htmlmin', 'versioning']);}
但是,在执行时出现以下错误:
Running "versioning:dist" (versioning) task
Warning: Unable to read "dest/js" file (Error code: EISDIR). Use --force to continue.
我理解这个错误的发生是因为 dest/js 不是一个文件而是一个目录,但是我不知道如何告诉 version 正确的文件名。是否有特定的 Grunt JS 格式来执行此操作?
最佳答案
似乎启用了一些额外的选项导致了上述错误。我已经纠正了这些并做了一些改变。运行下面的 grunt 文件,看看是否可以无错误地执行。
module.exports = function(grunt) {
grunt.initConfig({
clean : [ 'dest/js' ],
uglify : {
options : {
report : 'min',
mangle : true
},
my_target : {
files : [ {
src : 'src/js/*.js',
dest : 'dest/js/main.min.js'
} ]
}
},
cssmin : {
options : {
report : 'min'
},
minify : {
expand : true,
cwd : 'src/css',
src : '**/*.css',
dest : 'dest/css',
}
},
imagemin : {
dynamic : {
options : {
optimizationLevel : 7
},
files : [ {
expand : true,
cwd : 'src/assets',
src : [ '**/*.{png,jpg,gif}' ],
dest : 'dest/assets'
} ]
}
},
htmlmin : {
mini : {
options : {
removeComments : true,
collapseWhitespace : true,
collapseBooleanAttributes : true,
removeAttributeQuotes : true,
removeRedundantAttributes : true,
removeEmptyAttributes : true,
useShortDoctype : true
},
files : [ {
expand : true,
cwd : 'src',
src : '**/*.html',
dest : 'dest'
} ]
}
},
versioning : { // Task
options : { // Task options
cwd : 'public',
outputConfigDir : 'public/config'
},
dist : { // Target
options : { // Target options
},
files : [ {
assets : '<%= uglify.my_target.files %>',
key : 'global',
dest : 'dest/js',
type : 'js',
ext : '.js'
} ]
}
}
});
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-static-versioning');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-contrib-htmlmin');
grunt.registerTask('default', [ 'clean', 'uglify', 'cssmin', 'imagemin',
'htmlmin', 'versioning' ]);
}
关于javascript - Grunt Uglify 通配符和版本控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20100288/
我安装了 grunt 和 grunt cli,但仍然出现命令未找到错误 { "name": "angulartdd", "version": "1.0.0", "description":
我有一个使用“grunt-contrib-watch”和“grunt-exec”的 Grunt.js 文件,这是因为我想以一种独特的方式使用 handlebars 预编译器的一些自定义功能。 代码:
我正忙于尝试完成我正在运行的部署脚本。它可能有一半的时间有效,而且令人沮丧,因为我使用的大部分代码都不是我写的。我真的希望有一个我可以执行的较低级别的解决方法。 基本上发生的事情是我正在尝试执行 5
我想像在文档中定义的那样将参数传递给grunt-shell: module.exports = function(grunt) { // Configure Grunt grunt.initConfi
背景 我正在使用 Yeoman webapp 来搭建我的前端。 在 gruntfile 中,他们使用 grunt-rev 和 grunt-usemin Grunt-rev 将“修改”我的 Assets
我已经设置了grunt-eslint在我的 gruntfile.js 中,但是当我运行“grunt eslint”时,什么也没有发生。该任务看似即将开始,但 15 分钟后却停滞不前。 我的所有其他任务
我最近开始使用 grunt 做 JS 项目。 我有一个名为“grunt-contrib-jasmine”的插件用于 Jasmine 测试。我工作得很好,但我无法在浏览器中通过 specrunner 运
谁能告诉我这里做错了什么(我是 grunt 的新手)一个大学给我提供了一个基本的 gruntfile 设置 我已经安装了 node、js 和 grunt,但我不知道如何安装各种包(uglify、con
我正在尝试使用 grunt-contrib-watch和 grunt-rsync将任何文件更改上传到我的开发服务器。这是我的设置: var path = require('path'); module
尝试使用grunt-kill创建一个任务来终止我的 server-scorm 任务,并最终终止所有相关任务。这些说明非常短,因为它假设我知道有关 PID 文件的所有信息(我不知道,不是开发人员的错误)
我要么脑子一片空白,要么本该更复杂。 我正在尝试从 Grunt 任务运行 grunt-init,如下所示: grunt.registerTask('init', 'Scaffold various a
我有一个从玩家发射的射弹预制件,当它与“边界”碰撞时,它应该摧毁自己,当它击中“咕噜声”时,它应该摧毁自己和咕噜声。但是,当它碰到边界时,它会破坏自身和边界的对撞机。我创建了一个自定义标签脚本,允许我
module.exports = function(grunt){ grunt.initConfig({ pkg: grunt.file.readJSON('package.json'),
我已经加入了一个非营利性开源项目,想帮点忙,但我对 Grunt 不熟悉。我做了一些研究,但无法弄清楚为什么配置不起作用。 这是我正在尝试使用的插件。它允许应用多个后处理器,但我现在只需要 Autopr
下面的代码读取app/modules/中的每个子目录js的内容(例如app/modules/module1/js/, app/modules/module2/js/, aso.) 此脚本在不使用最后一
我正在尝试使用 grunt-exec 运行一个 javascript 测试运行程序,并传入一个已部署的链接变量。 我尝试通过使用 exec:setLink 设置环境变量 grunt.option('l
当我使用 grunt-contrib-watch 更改我的 js 文件时,我试图让 Grunt 重新加载它们。这是我的 Gruntfile: module.exports = function(gru
所以我的意思是: grunt.registerTask('default', ['default']); // CLI: grunt grunt.registerTask('serve', ['ser
我想创建一个通用的顶级 Gruntfile.js,配置为监视较少的文件更改。当less文件发生变化时,我想将其编译为css,然后在浏览器中实时加载css文件。我的功能正常,但我必须为每个项目复制 Gr
我正在使用 grunt-xmlpoke 更新 xml 文件。 xml 文件的路径作为参数提供。问题是文件部分中的第一个 WebConfigPath (键)被视为字符串。它更新了我的 xml 文件的本地
我是一名优秀的程序员,十分优秀!