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:
Download and unzip Framework7 GitHub repository to local folder
Install Node.js (if not installed)
Install Gulp (if not installed) by executing the following command in terminal:
$ npm install --global gulp
Now, we need to install required dependencies. Go to the folder with downloaded and unzipped Framework7 repository and execute in terminal:
$ npm install
- Copy
scripts/build-config.js
file to some place in the downloaded folder and rename it let's say toscripts/my-config.js
- 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;
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
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):
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 | |
Skeleton | framework7/components/skeleton/skeleton.js | |
Menu | framework7/components/menu/menu.js | |
Vi | framework7/components/vi/vi.js | |
Typography | framework7/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;