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. 'vi',
    52. 'typography',
    53. ],
    54. // include/exclude dark theme styles
    55. darkTheme: true,
    56. // include/exclude themes
    57. themes: [
    58. 'ios',
    59. 'md',
    60. ],
    61. // modify colors
    62. ios: {
    63. themeColor: '#007aff',
    64. colors: {
    65. red: '#ff3b30',
    66. green: '#4cd964',
    67. blue: '#007aff',
    68. pink: '#ff2d55',
    69. yellow: '#ffcc00',
    70. orange: '#ff9500',
    71. gray: '#8e8e93',
    72. white: '#ffffff',
    73. black: '#000000',
    74. },
    75. },
    76. md: {
    77. themeColor: '#2196f3',
    78. colors: {
    79. red: '#f44336',
    80. green: '#4caf50',
    81. blue: '#2196f3',
    82. pink: '#e91e63',
    83. yellow: '#ffeb3b',
    84. orange: '#ff9800',
    85. gray: '#9e9e9e',
    86. white: '#ffffff',
    87. black: '#000000',
    88. },
    89. },
    90. };
    91. 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

  9. If you are in hurry and want to see how its working then do follow step 1 to 4

    1. $ npm run build-core:dev

    The result is available in build/ folder.

  10. To build production version of Framework7:

    1. $ npm run build-core:prod

    Production version will be available in dist/ folder.

  11. Run Kitchen Sink with development environment

    1. $ npm run core:dev
  12. Run Kitchen Sink with Production environment

    1. $ npm run core:prod
  13. Kitchen Sink is live

    Visit http://localhost:3000/kitchen-sink/core/ From Youre Browser

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
Viframework7/components/vi/vi.js
Typographyframework7/components/typography/typography.js

Less.js

Framework7 styles are build 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. // include/exclude dark theme
  11. @includeDarkTheme: true;
  12. // iOS theme color
  13. @themeColorIos: #007aff;
  14. // MD theme color
  15. @themeColorMd: #2196f3;
  16. // Extra colors for iOS theme
  17. @colorsIos: red #ff3b30, green #4cd964, blue #007aff, pink #ff2d55, yellow #ffcc00, orange #ff9500, gray #8e8e93, white #ffffff, black #000000;
  18. // Extra colors for MD theme
  19. @colorsMd: red #f44336, green #4caf50, blue #2196f3, pink #e91e63, yellow #ffeb3b, orange #ff9800, gray #9e9e9e, white #ffffff, black #000000;
  20. // change to true to generate RTL styles
  21. @rtl: false;