fuse.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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: 'configure',
  19. describe: 'Use Configure mode',
  20. type: 'boolean',
  21. implies: 'd'
  22. })
  23. .help('h')
  24. .alias('h', 'help')
  25. .argv
  26. if (args.d) {
  27. // =============================================
  28. // DEVELOPER MODE
  29. // =============================================
  30. console.info(colors.bgWhite.black(' Starting Fuse in DEVELOPER mode... '))
  31. const nodemon = require('nodemon')
  32. // Client
  33. const fuse = fsbx.FuseBox.init({
  34. homeDir: './client',
  35. outFile: './assets/js/bundle.min.js',
  36. alias: {
  37. vue: 'vue/dist/vue.js'
  38. },
  39. plugins: [
  40. [ fsbx.SassPlugin({ includePaths: ['../core'] }), fsbx.CSSPlugin() ],
  41. fsbx.BabelPlugin({ comments: false, presets: ['es2015'] }),
  42. fsbx.JSONPlugin()
  43. ],
  44. debug: false,
  45. log: true
  46. })
  47. fuse.devServer('>index.js', {
  48. port: 4444,
  49. httpServer: false
  50. })
  51. // Server
  52. _.delay(() => {
  53. if (args.c) {
  54. nodemon({
  55. exec: 'node wiki configure',
  56. ignore: ['assets/', 'client/', 'data/', 'repo/', 'tests/'],
  57. ext: 'js json',
  58. watch: [
  59. 'configure.js'
  60. ],
  61. env: { 'NODE_ENV': 'development' }
  62. })
  63. } else {
  64. nodemon({
  65. script: './server.js',
  66. args: [],
  67. ignore: ['assets/', 'client/', 'data/', 'repo/', 'tests/'],
  68. ext: 'js json',
  69. watch: [
  70. 'controllers',
  71. 'libs',
  72. 'locales',
  73. 'middlewares',
  74. 'models',
  75. 'agent.js',
  76. 'server.js'
  77. ],
  78. env: { 'NODE_ENV': 'development' }
  79. })
  80. }
  81. }, 1000)
  82. } else {
  83. // =============================================
  84. // BUILD MODE
  85. // =============================================
  86. console.info(colors.bgWhite.black(' Starting Fuse in BUILD mode... '))
  87. const fuse = fsbx.FuseBox.init({
  88. homeDir: './client',
  89. outFile: './assets/js/bundle.min.js',
  90. plugins: [
  91. [ fsbx.SassPlugin({ outputStyle: 'compressed', includePaths: ['./node_modules/requarks-core'] }), fsbx.CSSPlugin() ],
  92. fsbx.BabelPlugin({
  93. config: {
  94. comments: false,
  95. presets: ['es2015']
  96. }
  97. }),
  98. fsbx.JSONPlugin(),
  99. fsbx.UglifyJSPlugin({
  100. compress: { unused: false }
  101. })
  102. ],
  103. debug: false,
  104. log: true
  105. })
  106. fuse.bundle('>index.js').then(() => {
  107. console.info(colors.green.bold('Assets compilation + bundling completed.'))
  108. }).catch(err => {
  109. console.error(colors.green.red(' X Bundle compilation failed! ' + err.message))
  110. process.exit(1)
  111. })
  112. }