fuse.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. 'use strict'
  2. /**
  3. * FUSEBOX
  4. *
  5. * Client & Server compiler / watcher
  6. */
  7. const fsbx = require('fuse-box')
  8. const colors = require('colors/safe')
  9. const _ = require('lodash')
  10. // Parse cmd arguments
  11. const args = require('yargs')
  12. .option('d', {
  13. alias: 'dev',
  14. describe: 'Start in Developer mode',
  15. type: 'boolean'
  16. })
  17. .option('c', {
  18. alias: 'dev-configure',
  19. describe: 'Start in Configure Developer mode',
  20. type: 'boolean'
  21. })
  22. .help('h')
  23. .alias('h', 'help')
  24. .argv
  25. if (args.d) {
  26. // =============================================
  27. // DEVELOPER MODE
  28. // =============================================
  29. console.info(colors.bgWhite.black(' Starting Fuse in DEVELOPER mode... '))
  30. const nodemon = require('nodemon')
  31. // Client
  32. const fuse = fsbx.FuseBox.init({
  33. homeDir: './client',
  34. outFile: './assets/js/bundle.min.js',
  35. alias: {
  36. vue: 'vue/dist/vue.js'
  37. },
  38. plugins: [
  39. [ fsbx.SassPlugin({ includePaths: ['../core'] }), fsbx.CSSPlugin() ],
  40. fsbx.BabelPlugin({ comments: false, presets: ['es2015'] }),
  41. fsbx.JSONPlugin()
  42. ],
  43. debug: false,
  44. log: true
  45. })
  46. fuse.devServer('>index.js', {
  47. port: 4444,
  48. httpServer: false
  49. })
  50. // Server
  51. _.delay(() => {
  52. nodemon({
  53. script: './server.js',
  54. args: [],
  55. ignore: ['assets/', 'client/', 'data/', 'repo/', 'tests/'],
  56. ext: 'js json',
  57. watch: [
  58. 'controllers',
  59. 'libs',
  60. 'locales',
  61. 'middlewares',
  62. 'models',
  63. 'agent.js',
  64. 'server.js'
  65. ],
  66. env: { 'NODE_ENV': 'development' }
  67. })
  68. }, 1000)
  69. } else if (args.c) {
  70. // =============================================
  71. // DEVELOPER MODE
  72. // =============================================
  73. console.info(colors.bgWhite.black(' Starting Fuse in CONFIGURE DEVELOPER mode... '))
  74. const nodemon = require('nodemon')
  75. // Client
  76. const fuse = fsbx.FuseBox.init({
  77. homeDir: './client',
  78. outFile: './assets/js/configure.min.js',
  79. alias: {
  80. vue: 'vue/dist/vue.js'
  81. },
  82. plugins: [
  83. [ fsbx.SassPlugin({ includePaths: ['../core'] }), fsbx.CSSPlugin() ],
  84. fsbx.BabelPlugin({ comments: false, presets: ['es2015'] }),
  85. fsbx.JSONPlugin()
  86. ],
  87. debug: false,
  88. log: true
  89. })
  90. fuse.devServer('>configure.js', {
  91. port: 4444,
  92. httpServer: false
  93. })
  94. // Server
  95. _.delay(() => {
  96. nodemon({
  97. exec: 'node wiki configure',
  98. ignore: ['assets/', 'client/', 'data/', 'repo/', 'tests/'],
  99. ext: 'js json',
  100. watch: [
  101. 'configure.js'
  102. ],
  103. env: { 'NODE_ENV': 'development' }
  104. })
  105. }, 1000)
  106. } else {
  107. // =============================================
  108. // BUILD MODE
  109. // =============================================
  110. console.info(colors.bgWhite.black(' Starting Fuse in BUILD mode... '))
  111. const fuse = fsbx.FuseBox.init({
  112. homeDir: './client',
  113. alias: {
  114. vue: 'vue/dist/vue.js'
  115. },
  116. plugins: [
  117. [ fsbx.SassPlugin({ outputStyle: 'compressed', includePaths: ['./node_modules/requarks-core'] }), fsbx.CSSPlugin() ],
  118. fsbx.BabelPlugin({
  119. config: {
  120. comments: false,
  121. presets: ['es2015']
  122. }
  123. }),
  124. fsbx.JSONPlugin(),
  125. fsbx.UglifyJSPlugin({
  126. compress: { unused: false }
  127. })
  128. ],
  129. debug: false,
  130. log: true
  131. })
  132. fuse.bundle({
  133. './assets/js/bundle.min.js': '>index.js',
  134. './assets/js/configure.min.js': '>configure.js'
  135. }).then(() => {
  136. console.info(colors.green.bold('Assets compilation + bundling completed.'))
  137. }).catch(err => {
  138. console.error(colors.green.red(' X Bundle compilation failed! ' + err.message))
  139. process.exit(1)
  140. })
  141. }