sails-linker.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /**
  2. * `tasks/config/sails-linker`
  3. *
  4. * ---------------------------------------------------------------
  5. *
  6. * Automatically inject <script> tags and <link> tags into the specified
  7. * specified HTML and/or EJS files. The specified delimiters (`startTag`
  8. * and `endTag`) determine the insertion points.
  9. *
  10. * For more information, see:
  11. * https://sailsjs.com/anatomy/tasks/config/sails-linker.js
  12. *
  13. */
  14. module.exports = function(grunt) {
  15. grunt.config.set('sails-linker', {
  16. // ╦╔═╗╦ ╦╔═╗╔═╗╔═╗╦═╗╦╔═╗╔╦╗
  17. // ║╠═╣╚╗╔╝╠═╣╚═╗║ ╠╦╝║╠═╝ ║
  18. // ╚╝╩ ╩ ╚╝ ╩ ╩╚═╝╚═╝╩╚═╩╩ ╩
  19. // ┌─ ┌─┐┬ ┬┌─┐┌┐┌┌┬┐ ┌─┐┬┌┬┐┌─┐ ┬┌─┐┬ ┬┌─┐┌─┐┌─┐┬─┐┬┌─┐┌┬┐ ─┐
  20. // │─── │ │ │├┤ │││ │───└─┐│ ││├┤ │├─┤└┐┌┘├─┤└─┐│ ├┬┘│├─┘ │ ───│
  21. // └─ └─┘┴─┘┴└─┘┘└┘ ┴ └─┘┴─┴┘└─┘ └┘┴ ┴ └┘ ┴ ┴└─┘└─┘┴└─┴┴ ┴ ─┘
  22. devJs: {
  23. options: {
  24. startTag: '<!--SCRIPTS-->',
  25. endTag: '<!--SCRIPTS END-->',
  26. fileTmpl: '<script src="%s"></script>',
  27. appRoot: '.tmp/public'
  28. },
  29. files: {
  30. '.tmp/public/**/*.html': require('../pipeline').jsFilesToInject,
  31. 'views/**/*.html': require('../pipeline').jsFilesToInject,
  32. 'views/**/*.ejs': require('../pipeline').jsFilesToInject
  33. }
  34. },
  35. devJsBuild: {
  36. options: {
  37. startTag: '<!--SCRIPTS-->',
  38. endTag: '<!--SCRIPTS END-->',
  39. fileTmpl: '<script src="%s"></script>',
  40. appRoot: '.tmp/public',
  41. // relative: true
  42. // ^^ Uncomment this if compiling assets for use in PhoneGap, CDN, etc.
  43. // (but be note that this can break custom font URLs)
  44. },
  45. files: {
  46. '.tmp/public/**/*.html': require('../pipeline').jsFilesToInject,
  47. 'views/**/*.html': require('../pipeline').jsFilesToInject,
  48. 'views/**/*.ejs': require('../pipeline').jsFilesToInject
  49. }
  50. },
  51. prodJs: {
  52. options: {
  53. startTag: '<!--SCRIPTS-->',
  54. endTag: '<!--SCRIPTS END-->',
  55. fileTmpl: '<script src="%s"></script>',
  56. appRoot: '.tmp/public'
  57. },
  58. files: {
  59. '.tmp/public/**/*.html': ['.tmp/public/min/production.min.js'],
  60. 'views/**/*.html': ['.tmp/public/min/production.min.js'],
  61. 'views/**/*.ejs': ['.tmp/public/min/production.min.js']
  62. }
  63. },
  64. prodJsBuild: {
  65. options: {
  66. startTag: '<!--SCRIPTS-->',
  67. endTag: '<!--SCRIPTS END-->',
  68. fileTmpl: '<script src="%s"></script>',
  69. appRoot: '.tmp/public',
  70. // relative: true
  71. // ^^ Uncomment this if compiling assets for use in PhoneGap, CDN, etc.
  72. // (but be note that this can break custom font URLs)
  73. },
  74. files: {
  75. '.tmp/public/**/*.html': ['.tmp/public/min/production.min.js'],
  76. 'views/**/*.html': ['.tmp/public/min/production.min.js'],
  77. 'views/**/*.ejs': ['.tmp/public/min/production.min.js']
  78. }
  79. },
  80. // ╔═╗╔╦╗╦ ╦╦ ╔═╗╔═╗╦ ╦╔═╗╔═╗╔╦╗╔═╗
  81. // ╚═╗ ║ ╚╦╝║ ║╣ ╚═╗╠═╣║╣ ║╣ ║ ╚═╗
  82. // ╚═╝ ╩ ╩ ╩═╝╚═╝╚═╝╩ ╩╚═╝╚═╝ ╩ ╚═╝
  83. // ┌─ ┬┌┐┌┌─┐┬ ┬ ┬┌┬┐┬┌┐┌┌─┐ ╔═╗╔═╗╔═╗ ┬ ┌─┐┌─┐┌┬┐┌─┐┬┬ ┌─┐┌┬┐ ╦ ╔═╗╔═╗╔═╗ ─┐
  84. // │─── │││││ │ │ │ │││││││ ┬ ║ ╚═╗╚═╗ ┌┼─ │ │ ││││├─┘││ ├┤ ││ ║ ║╣ ╚═╗╚═╗ ───│
  85. // └─ ┴┘└┘└─┘┴─┘└─┘─┴┘┴┘└┘└─┘ ╚═╝╚═╝╚═╝ └┘ └─┘└─┘┴ ┴┴ ┴┴─┘└─┘─┴┘ ╩═╝╚═╝╚═╝╚═╝ ─┘
  86. devStyles: {
  87. options: {
  88. startTag: '<!--STYLES-->',
  89. endTag: '<!--STYLES END-->',
  90. fileTmpl: '<link rel="stylesheet" href="%s">',
  91. appRoot: '.tmp/public'
  92. },
  93. files: {
  94. '.tmp/public/**/*.html': require('../pipeline').cssFilesToInject,
  95. 'views/**/*.html': require('../pipeline').cssFilesToInject,
  96. 'views/**/*.ejs': require('../pipeline').cssFilesToInject
  97. }
  98. },
  99. devStylesBuild: {
  100. options: {
  101. startTag: '<!--STYLES-->',
  102. endTag: '<!--STYLES END-->',
  103. fileTmpl: '<link rel="stylesheet" href="%s">',
  104. appRoot: '.tmp/public',
  105. // relative: true
  106. // ^^ Uncomment this if compiling assets for use in PhoneGap, CDN, etc.
  107. // (but be note that this can break custom font URLs)
  108. },
  109. files: {
  110. '.tmp/public/**/*.html': require('../pipeline').cssFilesToInject,
  111. 'views/**/*.html': require('../pipeline').cssFilesToInject,
  112. 'views/**/*.ejs': require('../pipeline').cssFilesToInject
  113. }
  114. },
  115. prodStyles: {
  116. options: {
  117. startTag: '<!--STYLES-->',
  118. endTag: '<!--STYLES END-->',
  119. fileTmpl: '<link rel="stylesheet" href="%s">',
  120. appRoot: '.tmp/public'
  121. },
  122. files: {
  123. '.tmp/public/index.html': ['.tmp/public/min/production.min.css'],
  124. 'views/**/*.html': ['.tmp/public/min/production.min.css'],
  125. 'views/**/*.ejs': ['.tmp/public/min/production.min.css']
  126. }
  127. },
  128. prodStylesBuild: {
  129. options: {
  130. startTag: '<!--STYLES-->',
  131. endTag: '<!--STYLES END-->',
  132. fileTmpl: '<link rel="stylesheet" href="%s">',
  133. appRoot: '.tmp/public',
  134. // relative: true
  135. // ^^ Uncomment this if compiling assets for use in PhoneGap, CDN, etc.
  136. // (but be note that this can break custom font URLs)
  137. },
  138. files: {
  139. '.tmp/public/index.html': ['.tmp/public/min/production.min.css'],
  140. 'views/**/*.html': ['.tmp/public/min/production.min.css'],
  141. 'views/**/*.ejs': ['.tmp/public/min/production.min.css']
  142. }
  143. },
  144. // ╔═╗╦═╗╔═╗╔═╗╔═╗╔╦╗╔═╗╦╦ ╔═╗╔╦╗ ╦ ╦╔╦╗╔╦╗╦ ╔╦╗╔═╗╔╦╗╔═╗╦ ╔═╗╔╦╗╔═╗╔═╗
  145. // ╠═╝╠╦╝║╣ ║ ║ ║║║║╠═╝║║ ║╣ ║║ ╠═╣ ║ ║║║║ ║ ║╣ ║║║╠═╝║ ╠═╣ ║ ║╣ ╚═╗
  146. // ╩ ╩╚═╚═╝╚═╝╚═╝╩ ╩╩ ╩╩═╝╚═╝═╩╝ ╩ ╩ ╩ ╩ ╩╩═╝ ╩ ╚═╝╩ ╩╩ ╩═╝╩ ╩ ╩ ╚═╝╚═╝
  147. // ┌─ ┌─┐┬ ┬┌─┐┌┐┌┌┬┐ ┌─┐┬┌┬┐┌─┐ ┬ ┌─┐┌┬┐┌─┐┌─┐┬ ┬ ┌┬┐┌─┐┌┬┐┌─┐┬ ┌─┐┌┬┐┌─┐┌─┐ ─┐
  148. // │─── │ │ │├┤ │││ │───└─┐│ ││├┤ │ │ │ ││├─┤└─┐├─┤ │ ├┤ │││├─┘│ ├─┤ │ ├┤ └─┐ ───│
  149. // └─ └─┘┴─┘┴└─┘┘└┘ ┴ └─┘┴─┴┘└─┘ ┴─┘└─┘─┴┘┴ ┴└─┘┴ ┴ ┴ └─┘┴ ┴┴ ┴─┘┴ ┴ ┴ └─┘└─┘ ─┘
  150. clientSideTemplates: {
  151. options: {
  152. startTag: '<!--TEMPLATES-->',
  153. endTag: '<!--TEMPLATES END-->',
  154. fileTmpl: '<script type="text/javascript" src="%s"></script>',
  155. appRoot: '.tmp/public'
  156. },
  157. files: {
  158. '.tmp/public/index.html': ['.tmp/public/jst.js'],
  159. 'views/**/*.html': ['.tmp/public/jst.js'],
  160. 'views/**/*.ejs': ['.tmp/public/jst.js']
  161. }
  162. },
  163. clientSideTemplatesBuild: {
  164. options: {
  165. startTag: '<!--TEMPLATES-->',
  166. endTag: '<!--TEMPLATES END-->',
  167. fileTmpl: '<script type="text/javascript" src="%s"></script>',
  168. appRoot: '.tmp/public',
  169. // relative: true
  170. // ^^ Uncomment this if compiling assets for use in PhoneGap, CDN, etc.
  171. // (but be note that this can break custom font URLs)
  172. },
  173. files: {
  174. '.tmp/public/index.html': ['.tmp/public/jst.js'],
  175. 'views/**/*.html': ['.tmp/public/jst.js'],
  176. 'views/**/*.ejs': ['.tmp/public/jst.js']
  177. }
  178. },
  179. });//</ grunt.config.set() >
  180. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  181. // This Grunt plugin is part of the default asset pipeline in Sails,
  182. // so it's already been automatically loaded for you at this point.
  183. //
  184. // Of course, you can always remove this Grunt plugin altogether by
  185. // deleting this file. But check this out: you can also use your
  186. // _own_ custom version of this Grunt plugin.
  187. //
  188. // Here's how:
  189. //
  190. // 1. Install it as a local dependency of your Sails app:
  191. // ```
  192. // $ npm install grunt-sails-linker --save-dev --save-exact
  193. // ```
  194. //
  195. //
  196. // 2. Then uncomment the following code:
  197. //
  198. // ```
  199. // // Load Grunt plugin from the node_modules/ folder.
  200. // grunt.loadNpmTasks('grunt-sails-linker');
  201. // ```
  202. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  203. };