如何使用Grunt在构建中包含映像
How to include images in a build using Grunt?
下面的脚本可以正确地连接并缩小css和js。
我需要在我的构建目录中复制一些文件夹及其文件和一些其他文件从根目录(没有缩小或连接)。例如目录icons
(如果可能的话包括子文件夹)、images
和根目录下的config.xml。
知道如何更改脚本吗?
module.exports = function (grunt) {
// project configuration
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
options: {
banner: '/* App: <%= pkg.name %> - Version: <%= pkg.version %> - Date: <%= grunt.template.today("dd-mm-yyyy") %> - Author: <%= pkg.author %> */'n'n'
}
},
cssmin: {
options: {
banner: '/* App: <%= pkg.name %> - Version: <%= pkg.version %> - Date: <%= grunt.template.today("dd-mm-yyyy") %> - Author: <%= pkg.author %> */'n'
}
},
useminPrepare: {
html: 'index.html',
options: {
dest: 'build'
}
},
usemin: { html: ['build/index.html'] },
copy: {
task0: {
src: 'index.html',
dest: 'build/index.html'
}
}
});
// load required modules
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-usemin');
// task definitions
grunt.registerTask('build', [
'copy:task0',
'useminPrepare',
'concat',
'cssmin',
'uglify',
'usemin'
]);
};
我用下面的脚本解决了这个问题。窍门是添加一些任务到copy
对象
task1: {
expand: true,
src: ['icons/**'],
dest: 'build/'
},
module.exports = function (grunt) {
// project configuration
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
options: {
banner: '/* App: <%= pkg.name %> - Date: <%= grunt.template.today("dd-mm-yyyy") %> - Author: <%= pkg.author %> */'n'n'
}
},
cssmin: {
options: {
banner: '/* App: <%= pkg.name %> - Date: <%= grunt.template.today("dd-mm-yyyy") %> - Author: <%= pkg.author %> */'n'
}
},
useminPrepare: {
html: 'index.html',
options: {
dest: 'build'
}
},
usemin: { html: ['build/index.html'] },
copy: {
task0: {
src: 'index.html',
dest: 'build/index.html'
},
task1: {
expand: true,
src: ['icons/**'],
dest: 'build/'
},
task2: {
expand: true,
src: ['img/**'],
dest: 'build/'
},
task3: {
src: 'config.xml',
dest: 'build/'
},
task4: {
src: 'widget.info',
dest: 'build/'
},
task5: {
src: 'config.js',
dest: 'build/'
},
},
clean: {
build: {
src: [".tmp"]
}
}
});
// load required modules
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-usemin');
grunt.loadNpmTasks('grunt-contrib-clean');
// task definitions
grunt.registerTask('build', [
'copy:task0',
'copy:task1',
'copy:task2',
'copy:task3',
'copy:task4',
'copy:task5',
'useminPrepare',
'concat',
'cssmin',
'uglify',
'usemin', // build
'clean' // clean temp folders
]);
};
帮助我的有用资源:
https://www.youtube.com/watch?v=gIbfDxF69c8grunt-contrib-build& # 39;不在NPM注册表
如何安装grunt以及如何使用它构建脚本
https://github.com/gruntjs/grunt-contrib-copy相关文章:
- 如何使jQuery中的悬停函数单独应用于数据库映像
- 无法在Safari中加载跨源映像(来自CloudFront)
- 有没有一种方法可以从chrome'的存储映像
- 如何在不必维护每个文件的两个版本的情况下,将通用JavaScript和映像部署到两个不同的EAR
- 在使用 Django 静态文件时动态设置映像时,只有绝对路径才能与 jquery 一起使用
- 获取我的数组中的每个 ID 映像 src
- 映像选取器在初始化时预选项
- 循环映像 IE7 问题
- 本地映像对象未在Javascript中正确初始化
- PHP抓取没有扩展的远程映像
- 如何在ASP.NET Response.BinaryWrite生成的Javascript中处理字节数组映像
- JQuery Error在出现错误时加载备用映像的事件
- 要映像的 Blob URL
- appendChild dataURI映像到window.open在IE中失败
- 在MySQL中存储映像路径与使用<img src=“"onError=“">
- 如何侦听跨域映像请求上的任何301/302重定向状态代码
- THREE.js:跨来源资源共享策略拒绝跨来源映像加载
- 将映像存储到本地存储
- 如何使用Grunt在构建中包含映像
- (reactjs)在react组件中包含本地映像