使用五个基本的grunt任务
Grunt大大简化了重复的前端开发任务。本文重点介绍了五个强大的Grunt插件,可提高效率和代码质量。 尽管存在其他任务跑步者(有关详细信息,请参见我们的《 Gulp.js简介》),但Grunt广泛的插件生态系统仍然是宝贵的资产。 新手咕unt?查看“用咕unt自动重复执行的任务”或官方咕unt入门指南。
>钥匙要点:
grunt-autoprefixer
:自动化供应商在CSS中的前缀,消除了添加浏览器兼容性前缀的繁琐的手动过程。grunt-uncss
:grunt-concurrent
grunt-wiredep
grunt-bower-install
:grunt-modernizr
:征服供应商前缀
grunt-autoprefixer
>
grunt-autoprefixer
browsers
此配置过程
>,以主要浏览器的最后两个版本为目标,加上IE 8、9和Opera 12.1。
2。<code class="language-javascript">grunt.initConfig({ autoprefixer: { options: { browsers: ['last 2 versions', 'ie 8', 'ie 9', 'Opera 12.1'] }, dist: { src: 'src/css/main.css', dest: 'dest/css/main-prefixed.css' } } });</code>:纤细的CSS
>
由UNCS驱动的 >选项(接受字面的班级名称或正则表格模式)以部分解决此问题。 复杂的选择器也可能导致错误;将它们隔离在单独的样式表中。 > Bower(JavaScript/CSS依赖管理器)需要手动将组件包含在您的HTML中。 基本配置: 这将依赖项注入 >创建自定义的现代化构建,其中包括您的项目使用的功能,从而产生较小,更高效的库。
>> main.css
main-prefixed.css
> >
无法通过JavaScript或用户交互动态添加CSS类。 使用grunt-uncss
限制:grunt-uncss
3。
grunt-wiredep
:轻松的依赖管理grunt-wiredep
>自动化这个,根据您的配置注入依赖项。<code class="language-javascript">grunt.initConfig({
autoprefixer: {
options: {
browsers: ['last 2 versions', 'ie 8', 'ie 9', 'Opera 12.1']
},
dist: {
src: 'src/css/main.css',
dest: 'dest/css/main-prefixed.css'
}
}
});</code>
index.html
>。 运行grunt-wiredep
后,您的HTML将包括以下几行,例如以下线
:优化现代化
> ModernIzr有助于检测浏览器对现代功能的支持。 grunt-modernizr
grunt-modernizr
>示例配置:<code class="language-javascript">grunt.initConfig({
wiredep: {
app: {
src: ['index.html']
}
}
});</code>
:速度的并行处理>
同时运行它们,可显着加快构建过程,尤其是在功能强大的机器上。grunt-concurrent
对于具有许多任务的项目,grunt-concurrent
>示例:<code class="language-javascript">grunt.initConfig({
modernizr: {
dist: {
devFile: 'path/to/modernizr.js',
outputFile: 'path/to/distribution-folder/custom-modernizr.js',
files: {
src: ['path/to/scripts/**/*.js', 'path/to/styles/**/*.css']
}
}
}
});</code>
>任务下同时运行的copy
,autoprefixer
>和test
>在concat
>任务下同时。
uncss
>此选择为增强基于咕unt的工作流程提供了坚实的基础。 探索庞大的咕unt插件生态系统,以发现更多的工具来简化您的开发过程。
以上是五项艰巨的任务,您会想念的!的详细内容。更多信息请关注PHP中文网其他相关文章!