Framework7 自定义构建
自定义构建
Framework7 带有 Gulp 构建器,允许构建自定义库版本,您可以在其中仅包含所需的组件/模块。我们需要以下内容:
下载并解压Framework7 GitHub 仓库到本地文件夹
安装Node.js(如果未安装)
通过在终端执行以下命令安装 Gulp(如果未安装):
npm install --global gulp
现在,我们需要安装所需的依赖项。进入下载并解压的 Framework7 仓库文件夹,并在终端执行:
npm install
- 复制
scripts/build-config.js
文件到下载文件夹中的某个位置并重命名,比如为scripts/my-config.js
- 打开此文件并删除您不需要的组件或修改颜色主题和包含的颜色:
/* my-config.js */ const config = { rtl: false, // change to true to generate RTL styles // remove any components you don't need components: [ // Modals 'dialog', 'popup', 'login-screen', 'popover', 'actions', 'sheet', 'toast', // Loaders 'preloader', 'progressbar', // List Components 'sortable', 'swipeout', 'accordion', 'contacts-list', 'virtual-list', 'list-index', // Timeline 'timeline', // Tabs 'tabs', // Panel 'panel', // Card 'card', // Chip 'chip', // Form Components 'form', 'input', 'checkbox', 'radio', 'toggle', 'range', 'stepper', 'smart-select', // Grid 'grid', // Pickers 'calendar', 'picker', // Page Components 'infinite-scroll', 'pull-to-refresh', // Data table 'data-table', // FAB 'fab', // Searchbar 'searchbar', // Messages 'messages', 'messagebar', // Swiper 'swiper', // Photo Browser 'photo-browser', // Notifications 'notification', // Autocomplete 'autocomplete', // Tooltip 'tooltip', // Gauge 'gauge', // Skeleton 'skeleton', // Color Picker 'color-picker', // Tree View 'treeview', // WYSIWYG Editor 'text-editor', // Pie Chart 'pie-chart', // Area Chart 'area-chart', // Breadcrumbs 'breadcrumbs', // Typography 'typography', ], // include/exclude dark theme styles darkTheme: true, // include/exclude light theme styles lightTheme: true, // include/exclude themes themes: [ 'ios', 'md', ], }; module.exports = config;
现在,我们已准备好构建 Framework7 的自定义版本。我们需要执行:
npm run build-core:prod -- --config scripts/my-config.js --output path/to/output/folder
这样就完成了。现在您应该会在指定的输出文件夹中看到新生成的 js 和 css 文件
ES 模块
如果您使用 Webpack 或 Rollup 等打包器,可以仅使用所需的 Framework7 JS 组件,而无需该构建过程,并且仅通过导入所需的组件:
// Import core framework
import Framework7 from 'framework7';
// Import additional components
import Searchbar from 'framework7/components/searchbar';
import Calendar from 'framework7/components/calendar';
import Popup from 'framework7/components/popup';
// Install F7 Components using .use() method on Framework7 class:
Framework7.use([Searchbar, Calendar, Popup]);
// Init app
var app = new Framework7({/*...*/});
以下组件可用于导入(所有其他组件都是核心的一部分):
组件 | 路径 | |
---|---|---|
对话框 | framework7/components/dialog | |
弹出窗口 | framework7/components/popup | |
登录屏幕 | framework7/components/login-screen | |
弹出框 | framework7/components/popover | |
动作 | framework7/components/actions | |
表单 | framework7/components/sheet | |
提示 | framework7/components/toast | |
预加载器 | framework7/components/preloader | |
进度条 | framework7/components/progressbar | |
可排序 | framework7/components/sortable | |
滑动删除 | framework7/components/swipeout | |
手风琴 | framework7/components/accordion | |
联系人列表 | framework7/components/contacts-list | |
虚拟列表 | framework7/components/virtual-list | |
列表索引 | framework7/components/list-index | |
时间线 | framework7/components/timeline | |
标签页 | framework7/components/tabs | |
面板 | framework7/components/panel | |
卡片 | framework7/components/card | |
芯片 | framework7/components/chip | |
表单 | framework7/components/form | |
输入 | framework7/components/input | |
复选框 | framework7/components/checkbox | |
单选按钮 | framework7/components/radio | |
开关 | framework7/components/toggle | |
范围 | framework7/components/range | |
步进器 | framework7/components/stepper | |
智能选择 | framework7/components/smart-select | |
网格 | framework7/components/grid | |
日历 | framework7/components/calendar | |
选择器 | framework7/components/picker | |
无限滚动 | framework7/components/infinite-scroll | |
下拉刷新 | framework7/components/pull-to-refresh | |
数据表格 | framework7/components/data-table | |
FAB | framework7/components/fab | |
搜索栏 | framework7/components/searchbar | |
消息 | framework7/components/messages | |
消息栏 | framework7/components/messagebar | |
Swiper | framework7/components/swiper | |
照片浏览器 | framework7/components/photo-browser | |
通知 | framework7/components/notification | |
自动完成 | framework7/components/autocomplete | |
提示框 | framework7/components/tooltip | |
计量表 | framework7/components/gauge | |
骨架 | framework7/components/skeleton | |
颜色选择器 | framework7/components/color-picker | |
树视图 | framework7/components/treeview | |
文本编辑器 | framework7/components/text-editor | |
饼图 | framework7/components/pie-chart | |
面积图 | framework7/components/area-chart | |
面包屑 | framework7/components/breadcrumbs | |
字体排印 | framework7/components/typography |
Less.js
Framework7 风格是使用Less.js如果您在应用程序/项目中使用 Less 和 NPM,则可以轻松创建仅包含您需要的组件的自定义 Framework7 样式表。
创建您自己的framework7.less
文件中指定 Framework7 的主颜色主题和所需颜色:
// core
@import 'framework7/less';
// import only components you need
@import 'framework7/components/searchbar/less';
@import 'framework7/components/calendar/less';
@import 'framework7/components/popup/less';
我们甚至可以进一步在自定义framework7.less
文件中指定 Framework7 的主颜色主题和所需颜色:
// core
@import 'framework7/less';
// import only components you need
@import 'framework7/components/searchbar/less';
@import 'framework7/components/calendar/less';
@import 'framework7/components/popup/less';
// include/exclude themes
@includeIosTheme: true;
@includeMdTheme: true;
// include/exclude dark theme
@includeDarkTheme: true;
// include/exclude light theme
@includeLightTheme: 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;