HackMD
  • Prime
    Prime  Full-text search on all paid plans
    Search anywhere and reach everything in a Workspace with Prime plan.
    Got it
    • Prime  Full-text search on all paid plans
      Prime  Full-text search on all paid plans
      Search anywhere and reach everything in a Workspace with Prime plan.
      Got it
      • Options
      • Versions and GitHub Sync
      • Transfer ownership
      • Delete this note
      • Template
      • Insert from template
      • Export
      • Dropbox
      • Google Drive
      • Gist
      • Import
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
      • Download
      • Markdown
      • HTML
      • Raw HTML
      • Sharing Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • More (Comment, Invitee)
      • Publishing
        Everyone on the web can find and read all notes of this public team.
        After the note is published, everyone on the web can find and read this note.
        See all published notes on profile page.
      • Commenting Enable
        Disabled Forbidden Owners Signed-in users Everyone
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
        • Everyone
      • Invitee
      • No invitee
    Menu Sharing Help
    Menu
    Options
    Versions and GitHub Sync Transfer ownership Delete this note
    Export
    Dropbox Google Drive Gist
    Import
    Dropbox Google Drive Gist Clipboard
    Download
    Markdown HTML Raw HTML
    Back
    Sharing
    Sharing Link copied
    /edit
    View mode
    • Edit mode
    • View mode
    • Book mode
    • Slide mode
    Edit mode View mode Book mode Slide mode
    Note Permission
    Read
    Owners
    • Owners
    • Signed-in users
    • Everyone
    Owners Signed-in users Everyone
    Write
    Owners
    • Owners
    • Signed-in users
    • Everyone
    Owners Signed-in users Everyone
    More (Comment, Invitee)
    Publishing
    Everyone on the web can find and read all notes of this public team.
    After the note is published, everyone on the web can find and read this note.
    See all published notes on profile page.
    More (Comment, Invitee)
    Commenting Enable
    Disabled Forbidden Owners Signed-in users Everyone
    Permission
    Owners
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Invitee
    No invitee
       owned this note    owned this note      
    Published Linked with GitHub
    Like4 BookmarkBookmarked
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # 使用 Nx 管理超大型前後端專案 / Mike(黃升煌) {%hackmd @ModernWeb/HkqZxb98v %} ### [簡報下載](https://www.slideshare.net/ssuser35b57e/modern-web-2020-nx) > 共筆從這開始 ### 想像中的軟體技術架構階層 ![](https://i.imgur.com/0royZcL.png) ### 大型專案的架構問題 > 及解決方法和思維 * 如何定義「大型」軟體專案 * 其實很難定義「大型」但可能包含 * 功能數量龐大(數百甚至數千個頁面) * 預算費用龐大(幾千萬到幾億台幣) * 牽扯到的人數眾多(數十到數千人) * 跨組織開發(數家公司共同作業) * 跨團隊開發(數個技術團隊共同作業) * 其他… * 每個人心裡的「大型」可能都有所不同 * 大型專案「架構」的問題 * 數以百計甚至千計的功能頁面及模組 * 組件跟組件或頁面跟頁面間錯綜復雜的相依關係 * 應用程式全部建置需花費極長的時間 * CICD流程 * 人工部署常常不小心手殘上錯版本 * 大型專案「人」的問題 * 團隊間使用技術不一致 * 固定卻冗長的開發規則 * 程式碼風格不一致 * 大型專案處理複雜問題的常見方法 * 使用Monorepo 架構 * 所有程式碼都 同一個code base 下 * 程式透明度增加 > 改壞可以回溯找到源頭 * 程式共享、增加可重用性 > 人利也可以重複使用 * 一致性的版本相依 ![](https://i.imgur.com/AyqxINy.png) * 開發規範與流程的一致化 * 導入程式碼產生器 * 將共用步驟、邏輯自動化 * 使用 Linter • 規範程式的相依規則 * 規範程式碼撰寫風格 - [ ] * Code Formatter * 確保程式碼風格的一致性 * 相依性管理 * 畫下專案與專案之間的相依關係 * 程式進行開發/修正/改版時,依照相依關係評估建置/部署策略 ![](https://i.imgur.com/yszGS3W.png) * 使用微前端(Micro Frontends)架構 * 將常用的共用功能抽成標準的 Web Components > 可以不使用任何框架 * 透過 Web Components 組合頁面功能 * 可以不限定任何框架,也就是任何框架下都可以使用 * 主流瀏覽器都支援(IE 11 有限度的支援) > 複雜的頁面IE 11執行速度慢 ### 使用Nrwl Nx 管理大型專案 > 工具特色介紹 * Nrwl Nx 簡介 * Monorepo 框架 * 提供一系列工具,來協助我們進行管理專案間的複雜關係 * 前端支援:Angular / React / Web Components * 後端支援:Express / Nestjs * [Vue 支援](https://github.com/ZachJW34/nx-plus/tree/master/libs/vue#readme) (感謝 Kuro) * 開始使用Nx (以Angular 範本為例) * 建立Nx 工作區 ``` npx create-nx-workspace@latest modern-web-nx-sample``` * 建立Angular 應用程式 ```ng g @nrwl/angular:application todos``` * 建立Angular 類別庫 ```ng g @nrwl/angular:library todos``` * [Nx Console](https://nx.dev/angular/cli/console) * 用來協助 快速執行各種Nx 相關指令 * 檢視專案間的相依性 * 檢視專案間的相依關係,以確保沒有錯誤的相依 ```nx dep-graph``` * 避免錯誤的專案相依 * nx.json 內可以設定每個專案的tag * tslint.json 內可以設定tag 之間相依關係約束 * 若專案的tags 相依關係設定有誤,執行nx lint 時就會報錯 * 自動程式碼排版 * Nx 使用prettier 進行程式碼自動排版 * 自訂規則都在prettierrc.json * 檢查是否有format 問題:```nx format:check``` * 強制format:```nx format:write``` * 使用affected 功能 * 針對變更的程式碼,分析需要重新建置的專案 * 只針對被影響的程式進行建置與測試等行為 * 可以視覺化影響範圍 * 使用affected 功能(指令參考) ```nx affected:[target] --base [commit] --head [commit]``` ```nx affected:apps``` ```nx affected:libs``` ```nx affected:build``` ```nx affected:e2e``` ```nx affected:tes``` ```nx affected:lint``` ```nx affected:dep-graph``` * affected 常用參數 ```--parallel```:平行處理執行工作 ```--maxParallel```:同時平行處理多少個工作 ```--all```:不評估被影響的範圍,針對所有專案執行指定工作 ```--exclude```:指定不執行工作的專案 ```--only-failed```:只執行 次失敗的專案工作 > 可用在單元測試 * Schematics 程式碼產生器 * 將常用的程式碼骨架透過程式碼產生器直接產生,節省不必要的複製貼上及人為錯誤 * 建立Schematic ``` npm run nx generate @nrwl/workspace:workspace-schematic my-schematic``` * 執行Schematic ``` npm run nx workspace-schematic [schematic-name] [options``` * 運算快取(Computation Caching) * 同樣的事情,不要做第二次 * 將異動後執行的結果cache 起來 * 未來同樣檔案內容與指令執行時 直接輸出cache 的結果 * 團隊開發大幅加速建置時間的好工具 * 預設cache 結果放在 **node_modules/.cache/nx** * 可設定nx.json 的```tasksRunnerOptions.default.options.cacheDirectory ```變更路徑 * 或使用[Nx Cloud](https://nx.app/) 放在雲端加速團隊開發 * 執行指令時可透過參數```--skip-cache``` 忽略cache ### Demo > Show me the code! [github](https://github.com/wellwind/modern-web-20-nrwl-nx-demo) * Dependency Graph * Tags Dependency * Format with Prettier * Nx Affected * Schematics * Computation Caching ### Resources * [Nx.Dev](https://nx.dev/)(Official Document) * [Nrwl Connect](https://connect.nrwl.io/)(course + eBook + video) * [Enterprise Angular](https://leanpub.com/enterprise-angular)(eBook) ###### tags: `MW20` `敏捷與管理` `PLM`

    Import from clipboard

    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 lost their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template is not available.


    Upgrade

    All
    • All
    • Team
    No template found.

    Create custom template


    Upgrade

    Delete template

    Do you really want to delete this template?

    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 via Google

    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

    Tutorials

    Book Mode Tutorial

    Slide Mode Tutorial

    YAML Metadata

    Contacts

    Facebook

    Twitter

    Feedback

    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

    Versions and GitHub Sync

    Sign in to link this note to GitHub Learn more
    This note is not linked with GitHub Learn more
     
    Add badge Pull Push GitHub Link Settings
    Upgrade now

    Version named by    

    More Less
    • Edit
    • Delete

    Note content is identical to the latest version.
    Compare with
      Choose a version
      No search result
      Version not found

    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. Learn more

         Sign in to GitHub

        HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.

        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
        Available push count

        Upgrade

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Upgrade

        Danger Zone

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

        Syncing

        Push failed

        Push successfully