Framework7 自訂建置

自訂建置

Framework7 附帶 Gulp 建置器,可建置自訂函式庫版本,您可以在其中只包含必要的元件/模組。我們需要下列項目

  1. 下載並解壓縮 Framework7 GitHub 儲存庫 到本機資料夾

  2. 安裝 Node.js(如果尚未安裝)

  3. 在終端機執行下列指令,安裝 Gulp(如果尚未安裝)

    $ npm install --global gulp
  4. 現在,我們需要安裝必要的相依性。前往已下載並解壓縮的 Framework7 儲存庫資料夾,並在終端機中執行

    $ npm install
  5. scripts/build-config.js 檔案複製到已下載資料夾中的某個位置,並將其重新命名為,例如 scripts/my-config.js
  6. 開啟此檔案並移除您不需要的元件,或修改色彩主題和包含的色彩
    /* 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;
    
  7. 現在,我們準備好建置 Framework7 的自訂版本。我們需要執行

    $ npm run build-core:prod -- --config scripts/my-config.js --output path/to/output/folder
  8. 全部完成。現在您應該會在指定的輸出資料夾中看到新產生的 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
LoginScreenframework7/components/login-screen
彈出視窗framework7/components/popover
Actionsframework7/components/actions
Sheetframework7/components/sheet
提示framework7/components/toast
載入中framework7/components/preloader
進度條framework7/components/progressbar
Sortableframework7/components/sortable
滑動刪除framework7/components/swipeout
Accordionframework7/components/accordion
ContactsListframework7/components/contacts-list
VirtualListframework7/components/virtual-list
ListIndexframework7/components/list-index
時間軸framework7/components/timeline
標籤framework7/components/tabs
Panelframework7/components/panel
Cardframework7/components/card
Chipframework7/components/chip
Formframework7/components/form
Inputframework7/components/input
核取方塊framework7/元件/核取方塊
單選按鈕framework7/元件/單選按鈕
切換framework7/元件/切換
範圍framework7/元件/範圍
階梯framework7/元件/步進器
智慧選取framework7/元件/智慧選取
格線framework7/元件/格線
行事曆framework7/元件/行事曆
選擇器framework7/元件/選取器
無限捲動framework7/元件/無限捲動
下拉更新framework7/元件/下拉更新
資料表格framework7/元件/資料表格
浮動動作按鈕framework7/元件/浮動動作按鈕
搜尋列framework7/元件/搜尋列
訊息framework7/元件/訊息
訊息列framework7/元件/訊息列
Swiperframework7/元件/滑動器
相片瀏覽器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;