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

  1. // remove any components you don't need
  2. components: [
  3. 'dialog',
  4. 'popup',
  5. 'login-screen',
  6. 'popover',
  7. 'actions',
  8. 'sheet',
  9. 'toast',
  10. 'preloader',
  11. 'progressbar',
  12. 'sortable',
  13. 'swipeout',
  14. 'accordion',
  15. 'contacts-list',
  16. 'virtual-list',
  17. 'timeline',
  18. 'tabs',
  19. 'panel',
  20. 'card',
  21. 'chip',
  22. 'form',
  23. 'input',
  24. 'checkbox',
  25. 'radio',
  26. 'toggle',
  27. 'range',
  28. 'stepper',
  29. 'smart-select',
  30. 'grid',
  31. 'calendar',
  32. 'picker',
  33. 'infinite-scroll',
  34. 'pull-to-refresh',
  35. 'lazy',
  36. 'data-table',
  37. 'fab',
  38. 'searchbar',
  39. 'messages',
  40. 'messagebar',
  41. 'swiper',
  42. 'photo-browser',
  43. 'notification',
  44. 'autocomplete',
  45. 'tooltip',
  46. 'gauge',
  47. 'vi',
  48. 'typography',
  49. ],
  50. // include/exclude dark theme styles
  51. darkTheme: true,
  52. // include/exclude themes
  53. themes: [
  54. 'ios',
  55. 'md',
  56. ],
  57. // modify colors
  58. ios: {
  59. themeColor: '#007aff',
  60. colors: {
  61. red: '#ff3b30',
  62. green: '#4cd964',
  63. blue: '#007aff',
  64. pink: '#ff2d55',
  65. yellow: '#ffcc00',
  66. orange: '#ff9500',
  67. gray: '#8e8e93',
  68. white: '#ffffff',
  69. black: '#000000',
  70. },
  71. },
  72. md: {
  73. themeColor: '#2196f3',
  74. colors: {
  75. red: '#f44336',
  76. green: '#4caf50',
  77. blue: '#2196f3',
  78. pink: '#e91e63',
  79. yellow: '#ffeb3b',
  80. orange: '#ff9800',
  81. gray: '#9e9e9e',
  82. white: '#ffffff',
  83. black: '#000000',
  84. },
  85. },
  86. };

  87. module.exports = config; ```

  88. 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.
  1. 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';

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

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

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

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

Component Path
Dialog framework7/components/dialog/dialog.js
Popup framework7/components/popup/popup.js
LoginScreen framework7/components/login-screen/login-screen.js
Popover framework7/components/popover/popover.js
Actions framework7/components/actions/actions.js
Sheet framework7/components/sheet/sheet.js
Toast framework7/components/toast/toast.js
Preloader framework7/components/preloader/preloader.js
Progressbar framework7/components/progressbar/progressbar.js
Sortable framework7/components/sortable/sortable.js
Swipeout framework7/components/swipeout/swipeout.js
Accordion framework7/components/accordion/accordion.js
ContactsList framework7/components/contacts-list/contacts-list.js
VirtualList framework7/components/virtual-list/virtual-list.js
ListIndex framework7/components/list-index/list-index.js
Timeline framework7/components/timeline/timeline.js
Tabs framework7/components/tabs/tabs.js
Panel framework7/components/panel/panel.js
Card framework7/components/card/card.js
Chip framework7/components/chip/chip.js
Form framework7/components/form/form.js
Input framework7/components/input/input.js
Checkbox framework7/components/checkbox/checkbox.js
Radio framework7/components/radio/radio.js
Toggle framework7/components/toggle/toggle.js
Range framework7/components/range/range.js
Stepper framework7/components/stepper/stepper.js
SmartSelect framework7/components/smart-select/smart-select.js
Grid framework7/components/grid/grid.js
Calendar framework7/components/calendar/calendar.js
Picker framework7/components/picker/picker.js
InfiniteScroll framework7/components/infinite-scroll/infinite-scroll.js
PullToRefresh framework7/components/pull-to-refresh/pull-to-refresh.js
Lazy framework7/components/lazy/lazy.js
DataTable framework7/components/data-table/data-table.js
Fab framework7/components/fab/fab.js
Searchbar framework7/components/searchbar/searchbar.js
Messages framework7/components/messages/messages.js
Messagebar framework7/components/messagebar/messagebar.js
Swiper framework7/components/swiper/swiper.js
PhotoBrowser framework7/components/photo-browser/photo-browser.js
Notification framework7/components/notification/notification.js
Autocomplete framework7/components/autocomplete/autocomplete.js
Tooltip framework7/components/tooltip/tooltip.js
Gauge framework7/components/gauge/gauge.js
Vi framework7/components/vi/vi.js
Typography framework7/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');

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

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

9. // include/exclude themes
10. @includeIosTheme: true;
11. @includeMdTheme: true;

13. // include/exclude dark theme
14. @includeDarkTheme: true;

16. // iOS theme color
17. @themeColorIos: #007aff;
18. // MD theme color
19. @themeColorMd: #2196f3;

21. // Extra colors for iOS theme
22. @colorsIos: red #ff3b30, green #4cd964, blue #007aff, pink #ff2d55, yellow #ffcc00, orange #ff9500, gray #8e8e93, white #ffffff, black #000000;

24. // Extra colors for MD theme
25. @colorsMd: red #f44336, green #4caf50, blue #2196f3, pink #e91e63, yellow #ffeb3b, orange #ff9800, gray #9e9e9e, white #ffffff, black #000000;

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