123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- 'use strict'
- /**
- * FUSEBOX
- *
- * Client & Server compiler / bundler / watcher
- */
- const autoprefixer = require('autoprefixer')
- const colors = require('colors/safe')
- const fsbx = require('fuse-box')
- const nodemon = require('nodemon')
- const fs = require('fs-extra')
- // -------------------------------------------------------
- // Parse cmd arguments
- // -------------------------------------------------------
- const args = require('yargs')
- .option('d', {
- alias: 'dev',
- describe: 'Start in Developer mode',
- type: 'boolean'
- })
- .help('h')
- .alias('h', 'help')
- .argv
- const dev = args.dev
- if (dev) {
- console.info(colors.bgWhite.black(' Starting Fuse in DEVELOPER mode... '))
- } else {
- console.info(colors.bgWhite.black(' Starting Fuse in BUILD mode... '))
- }
- // -------------------------------------------------------
- // BUILD VARS
- // -------------------------------------------------------
- const ALIASES = {
- 'brace-ext-modelist': 'brace/ext/modelist.js',
- 'simplemde': 'simplemde/dist/simplemde.min.js',
- 'socket-io-client': 'socket.io-client/dist/socket.io.js',
- 'vue': (dev) ? 'vue/dist/vue.js' : 'vue/dist/vue.min.js',
- 'vue-lodash': 'vue-lodash/dist/vue-lodash.min.js',
- 'vue-resource': (dev) ? 'vue-resource/dist/vue-resource.js' : 'vue-resource/dist/vue-resource.es2015.js'
- }
- const SHIMS = {
- jquery: {
- source: '../node_modules/jquery/dist/jquery.js',
- exports: '$'
- },
- diff2html: {
- source: '../node_modules/diff2html/dist/diff2html.min.js',
- exports: 'Diff2Html'
- },
- diff2htmlui: {
- source: '../node_modules/diff2html/dist/diff2html-ui.min.js',
- exports: 'Diff2HtmlUI'
- }
- }
- // -------------------------------------------------------
- // Global Tasks
- // -------------------------------------------------------
- console.info(colors.white('└── ') + colors.green('Running global tasks...'))
- let globalTasks = require('./fuse_tasks')
- // -------------------------------------------------------
- // FUSEBOX PRODUCER
- // -------------------------------------------------------
- const babelrc = fs.readJsonSync('.babelrc')
- const scssChain = [
- fsbx.SassPlugin({
- includePaths: ['node_modules'],
- outputStyle: dev ? 'nested' : 'compressed'
- }),
- fsbx.PostCSS([
- autoprefixer({
- remove: false,
- browsers: babelrc.presets[0][1].targets.browsers
- })
- ]),
- fsbx.CSSPlugin()
- ]
- globalTasks.then(() => {
- let fuse = fsbx.FuseBox.init({
- homeDir: '../client',
- output: '../assets/js/$name.js',
- alias: ALIASES,
- target: 'browser',
- tsConfig: './tsconfig.json',
- plugins: [
- fsbx.EnvPlugin({ NODE_ENV: (dev) ? 'development' : 'production' }),
- fsbx.VueComponentPlugin({
- script: fsbx.BabelPlugin(babelrc),
- template: fsbx.ConsolidatePlugin({
- engine: 'pug'
- }),
- style: scssChain
- }),
- scssChain,
- fsbx.BabelPlugin(babelrc),
- fsbx.JSONPlugin()
- ],
- debug: false,
- log: true
- })
- // -------------------------------------------------------
- // FUSEBOX DEV
- // -------------------------------------------------------
- if (dev) {
- fuse.dev({
- port: 5555,
- httpServer: false
- })
- }
- // -------------------------------------------------------
- // FUSEBOX BUNDLES
- // -------------------------------------------------------
- if (dev) {
- fuse.bundle('libs').shim(SHIMS).instructions('~ index.js')
- fuse.bundle('app').instructions('!> [index.js]').hmr({ reload: true }).watch()
- } else {
- fuse.bundle('bundle.min.js').shim(SHIMS).instructions('> index.js')
- }
- // -------------------------------------------------------
- // FUSEBOX RUN
- // -------------------------------------------------------
- fuse.run().then(() => {
- console.info(colors.green.bold('\nAssets compilation + bundling completed.'))
- if (dev) {
- nodemon({
- exec: 'node server',
- ignore: ['assets/', 'client/', 'data/', 'repo/', 'tests/', 'tools/'],
- ext: 'js json graphql',
- watch: ['server'],
- env: { 'NODE_ENV': 'development' }
- })
- }
- return true
- }).catch(err => {
- console.error(colors.red(' X Bundle compilation failed! ' + err.message))
- process.exit(1)
- })
- })
|