Framework7 Custom Build

Custom Build

Framework7 comes with Gulp builder that allows to build custom library version where you may include only required components/modules. We need the following:

  1. Download and unzip Framework7 GitHub repository to local folder

  2. Install Node.js (if not installed)

  3. Install Gulp (if not installed) by executing the following command in terminal:

    $ npm install --global gulp
  4. Now, we need to install required dependencies. Go to the folder with downloaded and unzipped Framework7 repository and execute in terminal:

    $ npm install
  5. Copy scripts/build-config.js file to some place in the downloaded folder and rename it let's say to scripts/my-config.js
  6. Open this file and remove components that you don't need or modify color theme and included colors:
    /* my-config.js */
    const config = {
      target: 'universal',
      rtl: false, // change to true to generate RTL styles
    
      // remove any components you don't need
      components: [
        'dialog',
        'popup',
        'login-screen',
        'popover',
        'actions',
        'sheet',
        'toast',
        'preloader',
        'progressbar',
        'sortable',
        'swipeout',
        'accordion',
        'contacts-list',
        'virtual-list',
        'timeline',
        'tabs',
        'panel',
        'card',
        'chip',
        'form',
        'input',
        'checkbox',
        'radio',
        'toggle',
        'range',
        'stepper',
        'smart-select',
        'grid',
        'calendar',
        'picker',
        'infinite-scroll',
        'pull-to-refresh',
        'lazy',
        'data-table',
        'fab',
        'searchbar',
        'messages',
        'messagebar',
        'swiper',
        'photo-browser',
        'notification',
        'autocomplete',
        'tooltip',
        'gauge',
        'skeleton',
        'menu',
        'vi',
        'elevation',
        'typography',
      ],
      // include/exclude dark theme styles
      darkTheme: true,
      // include/exclude themes
      themes: [
        'ios',
        'md',
        'aurora',
      ],
      // modify colors
      themeColor: '#007aff',
      colors: {
        red: '#ff3b30',
        green: '#4cd964',
        blue: '#2196f3',
        pink: '#ff2d55',
        yellow: '#ffcc00',
        orange: '#ff9500',
        purple: '#9c27b0',
        deeppurple: '#673ab7',
        lightblue: '#5ac8fa',
        teal: '#009688',
        lime: '#cddc39',
        deeporange: '#ff6b22',
        gray: '#8e8e93',
        white: '#ffffff',
        black: '#000000',
      },
    };
    
    module.exports = config;
    
  7. Now, we are ready to build custom version of Framework7. We need to execute:

    $ npm run build-core:prod -- --config scripts/my-config.js --output path/to/output/folder
  8. That is all. Now you should see newly generated js and css files in specified output folder

ES Modules

If you use bundler like Webpack or Rollup you can use only required Framework7 JS components without that build process and by importing only required components:

// Import core framework
import Framework7 from 'framework7';

// Import additional components
import Searchbar from 'framework7/components/searchbar/searchbar.js';
import Calendar from 'framework7/components/calendar/calendar.js';
import Popup from 'framework7/components/popup/popup.js';

// Install F7 Components using .use() method on Framework7 class:
Framework7.use([Searchbar, Calendar, Popup]);

// Init app
var app = new Framework7({/*...*/});

The following components are available for importing (all other components are part of the core):

ComponentPath
Dialogframework7/components/dialog/dialog.js
Popupframework7/components/popup/popup.js
LoginScreenframework7/components/login-screen/login-screen.js
Popoverframework7/components/popover/popover.js
Actionsframework7/components/actions/actions.js
Sheetframework7/components/sheet/sheet.js
Toastframework7/components/toast/toast.js
Preloaderframework7/components/preloader/preloader.js
Progressbarframework7/components/progressbar/progressbar.js
Sortableframework7/components/sortable/sortable.js
Swipeoutframework7/components/swipeout/swipeout.js
Accordionframework7/components/accordion/accordion.js
ContactsListframework7/components/contacts-list/contacts-list.js
VirtualListframework7/components/virtual-list/virtual-list.js
ListIndexframework7/components/list-index/list-index.js
Timelineframework7/components/timeline/timeline.js
Tabsframework7/components/tabs/tabs.js
Panelframework7/components/panel/panel.js
Cardframework7/components/card/card.js
Chipframework7/components/chip/chip.js
Formframework7/components/form/form.js
Inputframework7/components/input/input.js
Checkboxframework7/components/checkbox/checkbox.js
Radioframework7/components/radio/radio.js
Toggleframework7/components/toggle/toggle.js
Rangeframework7/components/range/range.js
Stepperframework7/components/stepper/stepper.js
SmartSelectframework7/components/smart-select/smart-select.js
Gridframework7/components/grid/grid.js
Calendarframework7/components/calendar/calendar.js
Pickerframework7/components/picker/picker.js
InfiniteScrollframework7/components/infinite-scroll/infinite-scroll.js
PullToRefreshframework7/components/pull-to-refresh/pull-to-refresh.js
Lazyframework7/components/lazy/lazy.js
DataTableframework7/components/data-table/data-table.js
Fabframework7/components/fab/fab.js
Searchbarframework7/components/searchbar/searchbar.js
Messagesframework7/components/messages/messages.js
Messagebarframework7/components/messagebar/messagebar.js
Swiperframework7/components/swiper/swiper.js
PhotoBrowserframework7/components/photo-browser/photo-browser.js
Notificationframework7/components/notification/notification.js
Autocompleteframework7/components/autocomplete/autocomplete.js
Tooltipframework7/components/tooltip/tooltip.js
Gaugeframework7/components/gauge/gauge.js
Skeletonframework7/components/skeleton/skeleton.js
Menuframework7/components/menu/menu.js
Viframework7/components/vi/vi.js
Typographyframework7/components/typography/typography.js

Less.js

Framework7 styles are built with Less.js. If you use Less and NPM in your app/project then you can easily create custom framework7 stylesheet with only components you need.

Create your own framework7.less file:

// core
@import url('path/to/node_modules/framework7/framework7.less');

// import only components you need
@import url('path/to/node_modules/framework7/components/searchbar/searchbar.less');
@import url('path/to/node_modules/framework7/components/calendar/calendar.less');
@import url('path/to/node_modules/framework7/components/popup/popup.less');

We can go even further and specify Framework7's main color theme and required colors in custom framework7.less file:

// core
@import url('path/to/node_modules/framework7/framework7.less');

// import only components you need
@import url('path/to/node_modules/framework7/components/searchbar/searchbar.less');
@import url('path/to/node_modules/framework7/components/calendar/calendar.less');
@import url('path/to/node_modules/framework7/components/popup/popup.less');

// include/exclude themes
@includeIosTheme: true;
@includeMdTheme: true;
@includeAuroraTheme: true;

// include/exclude dark theme
@includeDarkTheme: true;

// Theme color
@themeColor: #007aff;

// Extra colors
@colors: {
  red: #ff3b30;
  green: #4cd964;
  blue: #2196f3;
  pink: #ff2d55;
  yellow: #ffcc00;
  orange: #ff9500;
  purple: #9c27b0;
  deeppurple: #673ab7;
  lightblue: #5ac8fa;
  teal: #009688;
  lime: #cddc39;
  deeporange: #ff6b22;
  gray: #8e8e93;
  white: #ffffff;
  black: #000000;
};

// change to true to generate RTL styles
@rtl: false;