BalmJS

A flexible Front-End workflow

️⚡ Installation


npm install --global balm-cli
# See all available official templates
balm list

balm init <template-name> <project-name>
cd <project-name>
npm install
# OR `yarn`

# For development
npm run dev

# For production
npm run prod


cd /path/to/workspace

mkdir my-project && cd my-project
npm install --save-dev gulp balm
# OR `yarn add --dev gulp balm`

# Config balm
touch gulpfile.js

# For development
gulp

# For production
gulp --production

⚙ Configuration

gulpfile.js

const balm = require('balm');

balm.config = {
  roots: {
    source: 'src' // Source code root (Create a directory in project)
  },
  styles: {
    extname: 'css' // Main style extension: css,scss,less
  },
  scripts: {
    entry: './src/scripts/index.js' // The entry script (Create a javascript file)
  },
  assets: {
    root: '/path/to/your_remote_project', // Remote project root path
    mainDir: 'public' // Remote assets dir: '/path/to/your_remote_project/public'
  }
};

balm.go(mix => {
  if (balm.config.env.isProd) {
    // Publish assets(styles,scripts,images,fonts,media)
    // from local `${roots.target}/{css,js,img,font,media}`
    // to remote `${assets.root}/${assets.mainDir}`
    mix.publish();

    // Publish html templates
    // from local `${roots.target}/index.html`
    // to remote `${assets.root}/public/index.html`
    mix.publish('index.html', 'public');
  }
});


const balm = require('balm');

balm.config = {
  server: {
    open: true,
    proxyConfig: {
      context: '/api',
      options: {
        target: 'http://your.project.dev', // Target host
        changeOrigin: true // Needed for virtual hosted sites
      }
    }
  },
  roots: {
    source: 'src' // Source code root (Create a directory in project)
  },
  paths: {
    source: {
      css: 'styles', //   CSS dir: ./src/styles
      js: 'scripts', //    JS dir: ./src/scripts
      img: 'images', // Image dir: ./src/images
      font: 'fonts'  //  Font dir: ./src/fonts
    }
  },
  styles: {
    extname: 'css', // Main style extension: css,scss,less
    sprites: ['icons'] // Icons path: './src/images/icons'
  },
  scripts: {
    entry: {
      // Custom vendors
      // HTML: <script src="%PUBLIC_URL%/scripts/vendor/mylib.js"></script>
      mylib: [
        'your-project-vendors',
        'your-project-plugins'
      ],
      // The entry script (Create a javascript file)
      main: './src/scripts/index.js'
    }
  },
  assets: {
    root: '/path/to/your_remote_project', // Remote project root path
    mainDir: 'public', // Remote assets dir: '/path/to/your_remote_project/public'
    subDir: '', // Remote assets subdir: `/path/to/your_remote_project/public/${subDir}`
    cache: true
  }
};

balm.go(mix => {
  if (balm.config.env.isProd) {
    // Publish assets(styles,scripts,images,fonts,media)
    // from local `${roots.target}/{css,js,img,font,media}`
    // to `${assets.root}/${assets.mainDir}/${assets.subDir}`
    mix.publish();

    // Publish html templates
    // from local `${roots.target}/index.html`
    // to remote `${assets.root}/views/new-filename.blade.php`
    mix.publish([
      {
        input: 'index.html',
        output: 'views',
        renameOptions: {
          basename: 'new-filename',
          suffix: '.blade',
          extname: '.php'
        }
      }
    ]);
  }
});