選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Gruntfile_app.js 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /**
  2. * Created by robin on 11/10/15.
  3. */
  4. module.exports = function(grunt) {
  5. grunt.loadNpmTasks('grunt-contrib-clean');
  6. grunt.loadNpmTasks('grunt-usemin');
  7. grunt.loadNpmTasks('grunt-contrib-concat');
  8. grunt.loadNpmTasks('grunt-contrib-uglify');
  9. grunt.loadNpmTasks('grunt-contrib-copy');
  10. grunt.loadNpmTasks('grunt-contrib-cssmin');
  11. grunt.loadNpmTasks('grunt-contrib-less');
  12. var path = require('path');
  13. grunt.initConfig({
  14. globals: {
  15. releasePath: 'build/release/app',
  16. appFolder: 'app',
  17. staticFiles: [
  18. 'views/**/*.html',
  19. 'index.html',
  20. 'img/**',
  21. 'fonts/**'
  22. ]
  23. },
  24. useminPrepare: {
  25. release: '<%= globals.appFolder %>/index.html',
  26. options: {
  27. flow: {
  28. release: {
  29. steps: {
  30. 'js': [
  31. 'concat',
  32. {
  33. name: 'uglify',
  34. createConfig: function (context, block) {
  35. var cfg = {files: []},
  36. filesDef = {};
  37. filesDef.dest = path.join('<%= globals.releasePath %>', block.dest);
  38. filesDef.src = [];
  39. context.inFiles.forEach(function (inFile) {
  40. filesDef.src.push(path.join(context.inDir, inFile));
  41. });
  42. cfg.files.push(filesDef);
  43. return cfg;
  44. }
  45. }
  46. ],
  47. 'css': ['concat',
  48. {
  49. name: 'cssmin',
  50. createConfig: function (context, block) {
  51. var cfg = {files: []},
  52. filesDef = {};
  53. filesDef.dest = path.join('<%= globals.releasePath %>', block.dest);
  54. filesDef.src = [];
  55. context.inFiles.forEach(function (inFile) {
  56. filesDef.src.push(path.join(context.inDir, inFile));
  57. });
  58. cfg.files.push(filesDef);
  59. return cfg;
  60. }
  61. }],
  62. 'less': [
  63. {
  64. name: 'less',
  65. createConfig: function (context, block) {
  66. var cfg = {files: []},
  67. filesDef = {};
  68. context.options.generated.options = {
  69. cleancss: true
  70. };
  71. filesDef.dest = path.join('<%= globals.releasePath %>', block.dest);
  72. filesDef.src = [];
  73. context.inFiles.forEach(function (inFile) {
  74. filesDef.src.push(path.join(context.inDir, inFile));
  75. });
  76. cfg.files.push(filesDef);
  77. return cfg;
  78. }
  79. }
  80. ]
  81. },
  82. post: {
  83. }
  84. }
  85. }
  86. }
  87. },
  88. usemin: {
  89. html: '<%= globals.releasePath %>/index.html',
  90. options: {
  91. blockReplacements: {
  92. less: function (block) {
  93. return '<link rel=\"stylesheet\" href=\"' + block.dest + '\"/>';
  94. }
  95. }
  96. }
  97. },
  98. copy: {
  99. release: {
  100. files: [
  101. {
  102. expand: true,
  103. cwd:'<%= globals.appFolder %>/',
  104. src: ['<%= globals.staticFiles %>'],
  105. dest: '<%= globals.releasePath %>'
  106. },
  107. {
  108. expand: true,
  109. cwd:'<%= globals.appFolder %>/../bower_components/flat-ui/dist/fonts/',
  110. src: ['**'],
  111. dest: '<%= globals.releasePath %>/fonts/'
  112. }
  113. ]
  114. }
  115. },
  116. clean: {
  117. release: ['<%= globals.releasePath %>/*']
  118. }
  119. });
  120. grunt.registerTask('default', [
  121. 'clean:release',
  122. 'useminPrepare:release',
  123. 'concat:generated',
  124. 'uglify:generated',
  125. 'copy:release',
  126. 'cssmin:generated',
  127. 'less:generated',
  128. 'usemin'
  129. ]);
  130. };