如何将Yeoman输出的所有脚本、图像分组到自定义文件夹中
How to group Yeoman`s output`s all scripts,images to custom folder
我想将Yeoman工作流与我的python后端集成,我曾经将所有最小化/还原脚本、css、图像放在"静态"文件夹中,以供nginx缓存使用。
现在,我想做的是更改Yeoman的输出结构,将"bower_component"、"images"、"scripts"、"styles"放在"dist/static"文件夹中,并将else-html或tpl保留在"dist"文件夹。
我试图更改Grunt的配置,但失败了,以下是我的更改:
- 更改"应用程序"文件夹中的文件结构,如我所需,更新index.html和requirejs
- 根据"app"文件夹更新Gruntfiles.js中的文件结构
-
根据我的意愿更改Gruntfiles.js中所有与"yeoman.dist"相关的内容,将脚本、css、图像放在"static"文件夹中。
useminPrepare: { html: '<%= yeoman.app %>/index.html', options: { dest: '<%= yeoman.dist %>/static' } }, usemin: { html: ['<%= yeoman.dist %>/{,*/}*.html'], css: ['<%= yeoman.dist %>/static/styles/{,*/}*.css'], options: { dirs: ['<%= yeoman.dist %>/static'] } }, imagemin: { dist: { files: [{ expand: true, cwd: '<%= yeoman.app %>/static/images', src: '{,*/}*.{png,jpg,jpeg}', dest: '<%= yeoman.dist %>/static/images' }] } }, cssmin: { dist: { files: { '<%= yeoman.dist %>/static/styles/main.css': [ '.tmp/styles/{,*/}*.css', '<%= yeoman.app %>/static/styles/{,*/}*.css' ] } } }, htmlmin: { dist: { options: { /*removeCommentsFromCDATA: true, // https://github.com/yeoman/grunt-usemin/issues/44 //collapseWhitespace: true, collapseBooleanAttributes: true, removeAttributeQuotes: true, removeRedundantAttributes: true, useShortDoctype: true, removeEmptyAttributes: true, removeOptionalTags: true*/ }, files: [{ expand: true, cwd: '<%= yeoman.app %>', src: '*.html', dest: '<%= yeoman.dist %>' }] } }, copy: { dist: { files: [{ expand: true, dot: true, cwd: '<%= yeoman.app %>', dest: '<%= yeoman.dist %>', src: [ '*.{ico,txt}', '.htaccess', 'static/images/{,*/}*.{webp,gif}' ] }] } }, bower: { all: { rjsConfig: '<%= yeoman.app %>/static/scripts/main.js' } }, jst: { options: { amd: true }, compile: { files: { '.tmp/scripts/templates.js': ['<%= yeoman.app %>/static/scripts/templates/*.ejs'] } } }, rev: { dist: { files: { src: [ '<%= yeoman.dist %>/static/scripts/{,*/}*.js', '<%= yeoman.dist %>/static/styles/{,*/}*.css', '<%= yeoman.dist %>/static/images/{,*/}*.{png,jpg,jpeg,gif,webp}', '<%= yeoman.dist %>/static/styles/fonts/*' ] } } }
});
但是输出无法更新HTML以引用我们的concat/min/revved脚本文件,并且输出"bower_components"文件夹的路径存在问题。任何想了解源代码的人,请查看Github。
另一种方法是,我将所有nginx配置更改为使用这四个文件夹,而不是静态文件夹。有人能告诉我什么是符合我要求的最佳实践吗?谢谢
通过两个步骤修复了这个问题:
-
将'useminPrepare任务'dest'更改为'<%=yeoman.list%>'
-
将app/index.html中的"build:js"更改为"static/scripts/…"告诉"usemin"在哪里将js复制到"静态文件夹"
因此,现在我可以将所有min/unight/reverse脚本、图像、样式、bower_components放在"dest/static"文件夹中,以供nginx缓存使用。查看Github上的项目更新。
但要自动生成这种项目,最好的方法可能是自定义Yeoman生成器,而不是更改generator_backbone的输出,我稍后会尝试。
- 根据屏幕分辨率显示自定义背景图像
- Wordpress自定义元框多图像上传
- OpenLayers-自定义图像在一层上的马赛克
- 如何使用JS捕捉带有垂直线的自定义图像光标
- 在画布中创建自定义图像对象
- jquery UI工具提示的自定义背景图像
- 可以用我自己的自定义图像替换光标
- 使用带有自定义HTML元素的图像usemap
- 将带有自定义数据的图像上载到服务器
- 如何在javascript中使画布显示自定义图像作为背景
- 如何在这里的地图中添加自定义图像标记
- Google Plus通过javascript共享,带有自定义图像
- 使用Opera自定义base64图像光标-可能
- JS--自定义图像属性
- 如何在post数据中进行ajax调用-->图像和自定义数据(名称和值对)
- 嵌入视频,将黑色背景更改为自定义图像或第一个视频场景
- “未捕获的类型错误:无法读取未定义的属性'嵌入'”在 pdfMake pdf 引擎中使用自定义图像时
- 自定义图像作为单选按钮
- 谷歌交互式图表与图像自定义html工具提示
- 如何使用图像自定义滑块处理程序