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 | |
LoginScreen | framework7/components/login-screen | |
彈出視窗 | framework7/components/popover | |
Actions | framework7/components/actions | |
Sheet | framework7/components/sheet | |
提示 | framework7/components/toast | |
載入中 | framework7/components/preloader | |
進度條 | framework7/components/progressbar | |
Sortable | framework7/components/sortable | |
滑動刪除 | framework7/components/swipeout | |
Accordion | framework7/components/accordion | |
ContactsList | framework7/components/contacts-list | |
VirtualList | framework7/components/virtual-list | |
ListIndex | framework7/components/list-index | |
時間軸 | framework7/components/timeline | |
標籤 | framework7/components/tabs | |
Panel | framework7/components/panel | |
Card | framework7/components/card | |
Chip | framework7/components/chip | |
Form | framework7/components/form | |
Input | framework7/components/input | |
核取方塊 | framework7/元件/核取方塊 | |
單選按鈕 | framework7/元件/單選按鈕 | |
切換 | framework7/元件/切換 | |
範圍 | framework7/元件/範圍 | |
階梯 | framework7/元件/步進器 | |
智慧選取 | framework7/元件/智慧選取 | |
格線 | framework7/元件/格線 | |
行事曆 | framework7/元件/行事曆 | |
選擇器 | framework7/元件/選取器 | |
無限捲動 | framework7/元件/無限捲動 | |
下拉更新 | framework7/元件/下拉更新 | |
資料表格 | framework7/元件/資料表格 | |
浮動動作按鈕 | framework7/元件/浮動動作按鈕 | |
搜尋列 | framework7/元件/搜尋列 | |
訊息 | framework7/元件/訊息 | |
訊息列 | framework7/元件/訊息列 | |
Swiper | framework7/元件/滑動器 | |
相片瀏覽器 | framework7/元件/相片瀏覽器 | |
通知 | framework7/元件/通知 | |
自動完成 | framework7/元件/自動完成 | |
工具提示 | framework7/元件/工具提示 | |
量表 | framework7/元件/量表 | |
骨架 | framework7/元件/骨架 | |
顏色選取器 | framework7/元件/顏色選取器 | |
樹狀檢視 | framework7/元件/樹狀檢視 | |
文字編輯器 | framework7/元件/文字編輯器 | |
圓餅圖 | framework7/元件/圓餅圖 | |
區域圖表 | framework7/元件/折線圖 | |
麵包屑 | framework7/元件/麵包屑 | |
字體排印 | framework7/元件/排版 |
Less.js
Framework7 樣式是用 Less.js 建立的。如果您在應用程式/專案中使用 Less 和 NPM,則可以輕鬆建立自訂 Framework7 樣式表,僅包含您需要的元件。
建立您自己的 framework7.less
檔案
// 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;