凱文_hws
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- title: wordpress 前後分離 (前端篇) tags: udn type: slide slideOptions: spotlight: enabled: false touch: false --- # Wordpress 前後分離 前端篇 <font size="3">*(不會有後端篇)*</font> --- 用戶生活+ ![](https://i.imgur.com/ZInrP6W.png) ---- 簡訊插件 ![](https://i.imgur.com/nHGvANT.png) --- ## 目錄 - 現況 (前端做了什麼) - 工具 (Gulp, Vite) - 目的 (工具的目的) - 已知問題 --- ## 現況 - Docker - 處理畫面 - js & css & images & php - API - 前後分離,依靠 api 溝通 - 資料夾結構 ---- ### 畫面 <font size="5"> 跟原本的寫法沒有差別,php 寫 HTML,JS & CSS 來處理畫面與行為 </font> ![](https://i.imgur.com/DoxJer0.png) ---- ### 畫面 CSS, JS, 都有經過 minify 或 uglify <font size="3">PHP 引入 CSS & JS</font> ![](https://i.imgur.com/1iUUplM.png) <font size="3">CSS</font> ![](https://i.imgur.com/j9CDNam.png) <font size="3">JavaScirpt</font> ![](https://i.imgur.com/CvEOOxY.png) ---- ### API <font size="5"> 打 API 的同時需要帶上 cookie & nonce,PS 打 API 會自動夾帶 cookie,但 url 要注意 </font> ![](https://i.imgur.com/Y61R8EK.png) <font size="5"> 生活+ 的 api </font> <br/> <font size="5"> https://lab-edumall.udn.com/malllab/?rest_route=/udnwpsepuser/v1/auth/login </font> <br/> <img src="https://i.imgur.com/BoOsF7k.png" width="600px" /> <br/> ---- ### API (nonce) ```htmlmixed= <!-- php --> <script> window._nonce = "<?php echo wp_create_nonce('wp_rest'); ?>"; </script> ``` ```javascript= // js const url = `${window.location.pathname}?rest_route=/udnwpsepuser/v1/api/auth/my-profile`; const response = await fetch(url, { method: 'GET', headers: { "X-WP-Nonce": window?._nonce, } }); ``` ---- ## 資料夾結構 (生活 + 為例) <font size="4"> gulp - 開發時撰寫的檔案、gulp 的設定 <br/> plugins - 插件本體 (php, 處理過的 css,js) <br/> wordpress - wordpress 本體 </font> <br> ![](https://i.imgur.com/6JFbwoD.png) <!-- <img src="https://i.imgur.com/BQ9PKYZ.png" width="400" /> --> --- ## 工具 - Gulp - 專案: 用戶生活+ 的會員系統插件 - 全部都需要自己寫,比較麻煩 - Vite - 專案: 簡訊插件 - ps. 開發 Vue 時設定比較方便 ---- ### Gulp - tasks <img src="https://i.imgur.com/bogDfbL.png" width="700" /> <font size="3">taskClean 清除編譯檔案 | taskCleanCopyFiles 清除複製的編譯檔案</font> <font size="3">parallelTasks 編譯所有的檔案 | taskCopyAllFiles 複製所有的編譯檔案到 wordpress 裡面 (覆蓋舊檔案)</font> ---- ### Gulp - script <font size="4"> yarn dev - 監聽檔案改動並自動編譯 <br/> yarn build - 編譯成 production 的檔案 <br/> yarn clean - 刪除所有編譯出來的檔案 </font> ![](https://i.imgur.com/ICINWap.png) <a href="https://drive.google.com/file/d/1Q5I7kQ3cRwv4Z9K0UqiD38DPJZVobtIO/view?usp=share_link"> dev </a> <a href="https://drive.google.com/file/d/1ODeidmjS8m5k1M5iAzXiW7Y_Ezhrc1WM/view?usp=share_link"> build </a> ---- ### Vite 嘗試使用 Vue 開發 使用 [vite-php-setup](https://github.com/andrefelipe/vite-php-setup) 當作模板調整 (主要調整檔案輸出的路徑) ---- ### Vite - manifest.json <font size="3">透過此檔案可以知道所有資產的檔案名稱與路徑</font> <img src="https://i.imgur.com/xnATjZD.png" width="750" /> ---- ### Vite - helper.php <font size="5">用 manifest.json 組合出所有的 &lt; script &gt; 和 &lt; link &gt; </font> <img src="https://i.imgur.com/7vWe4YG.png" width="750" /> ---- ### Vite - SPA <font size="5">udn-sms-plugin-page.php 把所有 vite 產生的檔案引入</font> <img src="https://i.imgur.com/tCKYA89.png" width="750" /> ---- ### Vite - SPA <font size="5">全部相關的請求 (如下) 都用 udn-sms-plugin-page.php </font> <font size="1"> https://lab-edumall.udn.com/malllab/wp-admin/admin.php?page=udn-sms-options https://lab-edumall.udn.com/malllab/wp-admin/admin.php?page=udn-sms-record </font> <img src="https://i.imgur.com/4G6nXqz.png" width="750" /> --- ## 達成目的 ### 自動化 - 使用 Gulp 的專案就有寫複製功能,不需要手動處理 - 可以用比較新的功能,再透過工具處理相容性問題 - 用相關套件可以處理 CSS、JS 甚至圖片 (minify、uglify、tree shaking、.map 檔) --- ## 已知問題 目前沒有整合到 docker,並沒完全自動化 <font size="4"> 所以開發時需要打 script ,或者開發時要手動改成開發時需要的設定,而且現在編譯完成的檔案都會進入 git </font>

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully