gruntfile.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*jshint esversion: 6 */
  2. module.exports = function(grunt) {
  3. const path = require('path');
  4. grunt.initConfig({
  5. pkg: grunt.file.readJSON('package.json'),
  6. watch: {
  7. scripts: {
  8. files: ['src/**'],
  9. tasks: ['eslint', 'copy', 'concat', 'uglify', 'htmlmin', 'less:development', 'less:production']
  10. }
  11. },
  12. eslint: {
  13. options: {
  14. configFile: '.eslintrc.json',
  15. failOnError: false
  16. },
  17. target: [
  18. 'src/js/main/*.js',
  19. 'src/js/head/*.js',
  20. '../__common__/js/*.js'
  21. ],
  22. },
  23. stylelint: {
  24. options: {
  25. formatter: 'unix',
  26. },
  27. src: [
  28. 'src/less/**/*.less',
  29. ]
  30. },
  31. copy: {
  32. js: {
  33. expand: true,
  34. cwd: './node_modules',
  35. dest: './js/',
  36. flatten: true,
  37. filter: 'isFile',
  38. timestamp: true,
  39. src: [
  40. './leaflet/dist/leaflet.js',
  41. ]
  42. },
  43. css: {
  44. expand: true,
  45. cwd: './node_modules',
  46. dest: './css/',
  47. flatten: true,
  48. filter: 'isFile',
  49. timestamp: true,
  50. src: [
  51. './leaflet/dist/leaflet.css',
  52. ]
  53. },
  54. leaflet_images: {
  55. expand: true,
  56. cwd: './node_modules',
  57. dest: './css/images/',
  58. flatten: true,
  59. filter: 'isFile',
  60. timestamp: true,
  61. src: [
  62. './leaflet/dist/images/*.png',
  63. ]
  64. },
  65. },
  66. concat: {
  67. head_and_body: {
  68. options: {
  69. separator: ';'
  70. },
  71. files: {
  72. 'js/searxng.head.js': ['src/js/head/*.js'],
  73. 'js/searxng.js': ['src/js/main/*.js', '../__common__/js/*.js', './node_modules/autocomplete-js/dist/autocomplete.js']
  74. }
  75. }
  76. },
  77. uglify: {
  78. options: {
  79. output: {
  80. comments: 'some'
  81. },
  82. ie8: false,
  83. warnings: true,
  84. compress: false,
  85. mangle: true,
  86. sourceMap: true
  87. },
  88. dist: {
  89. files: {
  90. 'js/searxng.head.min.js': ['js/searxng.head.js'],
  91. 'js/searxng.min.js': ['js/searxng.js']
  92. }
  93. }
  94. },
  95. htmlmin: {
  96. dist: {
  97. options: {
  98. removeComments: true,
  99. collapseWhitespace: true
  100. },
  101. files: {
  102. '../../../templates/__common__/searxng-wordmark.min.svg': 'src/svg/searxng-wordmark.svg'
  103. }
  104. }
  105. },
  106. webfont: {
  107. icons: {
  108. // src: 'node_modules/ionicons-npm/src/*.svg',
  109. src: [
  110. 'node_modules/ionicons-npm/src/navicon-round.svg',
  111. 'node_modules/ionicons-npm/src/search.svg',
  112. 'node_modules/ionicons-npm/src/play.svg',
  113. 'node_modules/ionicons-npm/src/link.svg',
  114. 'node_modules/ionicons-npm/src/chevron-up.svg',
  115. 'node_modules/ionicons-npm/src/chevron-left.svg',
  116. 'node_modules/ionicons-npm/src/chevron-right.svg',
  117. 'node_modules/ionicons-npm/src/arrow-down-a.svg',
  118. 'node_modules/ionicons-npm/src/arrow-up-a.svg',
  119. 'node_modules/ionicons-npm/src/arrow-swap.svg',
  120. 'node_modules/ionicons-npm/src/telephone.svg',
  121. 'node_modules/ionicons-npm/src/android-arrow-dropdown.svg',
  122. 'node_modules/ionicons-npm/src/android-globe.svg',
  123. 'node_modules/ionicons-npm/src/android-time.svg',
  124. 'node_modules/ionicons-npm/src/location.svg',
  125. 'node_modules/ionicons-npm/src/alert-circled.svg',
  126. 'node_modules/ionicons-npm/src/android-alert.svg',
  127. 'node_modules/ionicons-npm/src/ios-film-outline.svg',
  128. 'node_modules/ionicons-npm/src/music-note.svg',
  129. 'node_modules/ionicons-npm/src/ion-close-round.svg',
  130. 'node_modules/ionicons-npm/src/android-more-vertical.svg',
  131. 'src/fonts/magnet.svg',
  132. 'node_modules/ionicons-npm/src/android-close.svg',
  133. ],
  134. dest: 'fonts',
  135. destLess: 'src/generated',
  136. options: {
  137. font: 'ion',
  138. hashes : true,
  139. syntax: 'bem',
  140. styles : 'font,icon',
  141. types : 'eot,woff2,woff,ttf,svg',
  142. order : 'eot,woff2,woff,ttf,svg',
  143. stylesheets : ['css', 'less'],
  144. relativeFontPath : '../fonts/',
  145. autoHint : false,
  146. normalize : false,
  147. // ligatures : true,
  148. optimize : true,
  149. // fontHeight : 400,
  150. rename : function(name) {
  151. basename = path.basename(name);
  152. if (basename === 'android-alert.svg') {
  153. return 'error.svg';
  154. }
  155. if (basename === 'alert-circled.svg') {
  156. return 'warning.svg';
  157. }
  158. if (basename === 'ion-close-round.svg') {
  159. return 'close.svg';
  160. }
  161. return basename.replace(/(ios|md|android)-/i, '');
  162. },
  163. templateOptions: {
  164. baseClass: 'ion-icon',
  165. classPrefix: 'ion-'
  166. }
  167. }
  168. }
  169. },
  170. less: {
  171. development: {
  172. options: {
  173. paths: ["less"],
  174. },
  175. files: {
  176. "css/searxng.css": "src/less/style.less",
  177. "css/searxng-rtl.css": "src/less/style-rtl.less"
  178. }
  179. },
  180. production: {
  181. options: {
  182. paths: ["less"],
  183. plugins: [
  184. new (require('less-plugin-clean-css'))()
  185. ],
  186. sourceMap: true,
  187. sourceMapURL: (name) => { const s = name.split('/'); return s[s.length - 1] + '.map';},
  188. outputSourceFiles: false,
  189. sourceMapRootpath: '../',
  190. },
  191. files: {
  192. "css/searxng.min.css": "src/less/style.less",
  193. "css/searxng-rtl.min.css": "src/less/style-rtl.less"
  194. }
  195. },
  196. },
  197. });
  198. grunt.loadNpmTasks('grunt-contrib-watch');
  199. grunt.loadNpmTasks('grunt-contrib-copy');
  200. grunt.loadNpmTasks('grunt-contrib-uglify');
  201. grunt.loadNpmTasks('grunt-contrib-htmlmin');
  202. grunt.loadNpmTasks('grunt-contrib-jshint');
  203. grunt.loadNpmTasks('grunt-contrib-concat');
  204. grunt.loadNpmTasks('grunt-contrib-less');
  205. grunt.loadNpmTasks('grunt-contrib-cssmin');
  206. grunt.loadNpmTasks('grunt-webfont');
  207. grunt.loadNpmTasks('grunt-stylelint');
  208. grunt.loadNpmTasks('grunt-eslint');
  209. grunt.registerTask('test', ['jshint']);
  210. grunt.registerTask('default', [
  211. 'eslint',
  212. 'stylelint',
  213. 'copy',
  214. 'concat',
  215. 'uglify',
  216. 'htmlmin',
  217. 'less:development',
  218. 'less:production'
  219. ]);
  220. };