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:

    1. $ 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:

    1. $ 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:

    1. /* my-config.js */
    2. const config = {
    3. target: 'universal',
    4. rtl: false, // change to true to generate RTL styles
    5. // remove any components you don't need
    6. components: [
    7. 'dialog',
    8. 'popup',
    9. 'login-screen',
    10. 'popover',
    11. 'actions',
    12. 'sheet',
    13. 'toast',
    14. 'preloader',
    15. 'progressbar',
    16. 'sortable',
    17. 'swipeout',
    18. 'accordion',
    19. 'contacts-list',
    20. 'virtual-list',
    21. 'timeline',
    22. 'tabs',
    23. 'panel',
    24. 'card',
    25. 'chip',
    26. 'form',
    27. 'input',
    28. 'checkbox',
    29. 'radio',
    30. 'toggle',
    31. 'range',
    32. 'stepper',
    33. 'smart-select',
    34. 'grid',
    35. 'calendar',
    36. 'picker',
    37. 'infinite-scroll',
    38. 'pull-to-refresh',
    39. 'lazy',
    40. 'data-table',
    41. 'fab',
    42. 'searchbar',
    43. 'messages',
    44. 'messagebar',
    45. 'swiper',
    46. 'photo-browser',
    47. 'notification',
    48. 'autocomplete',
    49. 'tooltip',
    50. 'gauge',
    51. 'skeleton',
    52. 'menu',
    53. 'vi',
    54. 'elevation',
    55. 'typography',
    56. ],
    57. // include/exclude dark theme styles
    58. darkTheme: true,
    59. // include/exclude themes
    60. themes: [
    61. 'ios',
    62. 'md',
    63. 'aurora',
    64. ],
    65. // modify colors
    66. themeColor: '#007aff',
    67. colors: {
    68. red: '#ff3b30',
    69. green: '#4cd964',
    70. blue: '#2196f3',
    71. pink: '#ff2d55',
    72. yellow: '#ffcc00',
    73. orange: '#ff9500',
    74. purple: '#9c27b0',
    75. deeppurple: '#673ab7',
    76. lightblue: '#5ac8fa',
    77. teal: '#009688',
    78. lime: '#cddc39',
    79. deeporange: '#ff6b22',
    80. gray: '#8e8e93',
    81. white: '#ffffff',
    82. black: '#000000',
    83. },
    84. };
    85. module.exports = config;
  7. Now, we are ready to build custom version of Framework7. We need to execute:

    1. $ 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:

  1. // Import core framework
  2. import Framework7 from 'framework7';
  3. // Import additional components
  4. import Searchbar from 'framework7/components/searchbar/searchbar.js';
  5. import Calendar from 'framework7/components/calendar/calendar.js';
  6. import Popup from 'framework7/components/popup/popup.js';
  7. // Install F7 Components using .use() method on Framework7 class:
  8. Framework7.use([Searchbar, Calendar, Popup]);
  9. // Init app
  10. 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:

  1. // core
  2. @import url('path/to/node_modules/framework7/framework7.less');
  3. // import only components you need
  4. @import url('path/to/node_modules/framework7/components/searchbar/searchbar.less');
  5. @import url('path/to/node_modules/framework7/components/calendar/calendar.less');
  6. @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:

  1. // core
  2. @import url('path/to/node_modules/framework7/framework7.less');
  3. // import only components you need
  4. @import url('path/to/node_modules/framework7/components/searchbar/searchbar.less');
  5. @import url('path/to/node_modules/framework7/components/calendar/calendar.less');
  6. @import url('path/to/node_modules/framework7/components/popup/popup.less');
  7. // include/exclude themes
  8. @includeIosTheme: true;
  9. @includeMdTheme: true;
  10. @includeAuroraTheme: true;
  11. // include/exclude dark theme
  12. @includeDarkTheme: true;
  13. // Theme color
  14. @themeColor: #007aff;
  15. // Extra colors
  16. @colors: {
  17. red: #ff3b30;
  18. green: #4cd964;
  19. blue: #2196f3;
  20. pink: #ff2d55;
  21. yellow: #ffcc00;
  22. orange: #ff9500;
  23. purple: #9c27b0;
  24. deeppurple: #673ab7;
  25. lightblue: #5ac8fa;
  26. teal: #009688;
  27. lime: #cddc39;
  28. deeporange: #ff6b22;
  29. gray: #8e8e93;
  30. white: #ffffff;
  31. black: #000000;
  32. };
  33. // change to true to generate RTL styles
  34. @rtl: false;