gruntfile.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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', '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. webfont: {
  96. icons: {
  97. // src: 'node_modules/ionicons-npm/src/*.svg',
  98. src: [
  99. 'node_modules/ionicons-npm/src/navicon-round.svg',
  100. 'node_modules/ionicons-npm/src/search.svg',
  101. 'node_modules/ionicons-npm/src/play.svg',
  102. 'node_modules/ionicons-npm/src/link.svg',
  103. 'node_modules/ionicons-npm/src/chevron-up.svg',
  104. 'node_modules/ionicons-npm/src/chevron-left.svg',
  105. 'node_modules/ionicons-npm/src/chevron-right.svg',
  106. 'node_modules/ionicons-npm/src/arrow-down-a.svg',
  107. 'node_modules/ionicons-npm/src/arrow-up-a.svg',
  108. 'node_modules/ionicons-npm/src/arrow-swap.svg',
  109. 'node_modules/ionicons-npm/src/telephone.svg',
  110. 'node_modules/ionicons-npm/src/android-arrow-dropdown.svg',
  111. 'node_modules/ionicons-npm/src/android-globe.svg',
  112. 'node_modules/ionicons-npm/src/android-time.svg',
  113. 'node_modules/ionicons-npm/src/location.svg',
  114. 'node_modules/ionicons-npm/src/alert-circled.svg',
  115. 'node_modules/ionicons-npm/src/android-alert.svg',
  116. 'node_modules/ionicons-npm/src/ios-film-outline.svg',
  117. 'node_modules/ionicons-npm/src/music-note.svg',
  118. 'node_modules/ionicons-npm/src/ion-close-round.svg',
  119. 'node_modules/ionicons-npm/src/android-more-vertical.svg',
  120. 'src/fonts/magnet.svg',
  121. 'node_modules/ionicons-npm/src/android-close.svg',
  122. ],
  123. dest: 'fonts',
  124. destLess: 'src/generated',
  125. options: {
  126. font: 'ion',
  127. hashes : true,
  128. syntax: 'bem',
  129. styles : 'font,icon',
  130. types : 'eot,woff2,woff,ttf,svg',
  131. order : 'eot,woff2,woff,ttf,svg',
  132. stylesheets : ['css', 'less'],
  133. relativeFontPath : '../fonts/',
  134. autoHint : false,
  135. normalize : false,
  136. // ligatures : true,
  137. optimize : true,
  138. // fontHeight : 400,
  139. rename : function(name) {
  140. basename = path.basename(name);
  141. if (basename === 'android-alert.svg') {
  142. return 'error.svg';
  143. }
  144. if (basename === 'alert-circled.svg') {
  145. return 'warning.svg';
  146. }
  147. if (basename === 'ion-close-round.svg') {
  148. return 'close.svg';
  149. }
  150. return basename.replace(/(ios|md|android)-/i, '');
  151. },
  152. templateOptions: {
  153. baseClass: 'ion-icon',
  154. classPrefix: 'ion-'
  155. }
  156. }
  157. }
  158. },
  159. less: {
  160. development: {
  161. options: {
  162. paths: ["less"],
  163. },
  164. files: {
  165. "css/searxng.css": "src/less/style.less",
  166. "css/searxng-rtl.css": "src/less/style-rtl.less"
  167. }
  168. },
  169. production: {
  170. options: {
  171. paths: ["less"],
  172. plugins: [
  173. new (require('less-plugin-clean-css'))()
  174. ],
  175. sourceMap: true,
  176. sourceMapURL: (name) => { const s = name.split('/'); return s[s.length - 1] + '.map';},
  177. outputSourceFiles: false,
  178. sourceMapRootpath: '../',
  179. },
  180. files: {
  181. "css/searxng.min.css": "src/less/style.less",
  182. "css/searxng-rtl.min.css": "src/less/style-rtl.less"
  183. }
  184. },
  185. },
  186. });
  187. grunt.loadNpmTasks('grunt-contrib-watch');
  188. grunt.loadNpmTasks('grunt-contrib-copy');
  189. grunt.loadNpmTasks('grunt-contrib-uglify');
  190. grunt.loadNpmTasks('grunt-contrib-jshint');
  191. grunt.loadNpmTasks('grunt-contrib-concat');
  192. grunt.loadNpmTasks('grunt-contrib-less');
  193. grunt.loadNpmTasks('grunt-contrib-cssmin');
  194. grunt.loadNpmTasks('grunt-webfont');
  195. grunt.loadNpmTasks('grunt-stylelint');
  196. grunt.loadNpmTasks('grunt-eslint');
  197. grunt.registerTask('test', ['jshint']);
  198. grunt.registerTask('default', [
  199. 'eslint',
  200. 'stylelint',
  201. 'copy',
  202. 'concat',
  203. 'uglify',
  204. 'less:development',
  205. 'less:production'
  206. ]);
  207. };