MOPCON
      • 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
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners 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 New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
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
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners 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
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # vite: Make web dev fast again. - Kuro Hsu {%hackmd rG6pzIawQKe5cHU4rycgYg %} :::success :::spoiler TableOfContent [TOC] ::: [vitejs/vite](https://github.com/vitejs/vite) [重新認識 Vue.js](https://book.vue.tw/) [簡報](https://speakerdeck.com/kurotanshi/mopcon-2020-vite-make-web-dev-fast-again) ## vite 是什麼?解決了什麼問題 - vite 發音 /vit/,法語「快速」的意思 - 提供開發者快速啟動、即時更新的開發工具 >加速開發,但不是加速體驗速度 - 安裝即使用,預設無設定檔 - 加速你的開發體驗,不加速你的應用效能 ### 作者 尤雨溪 (Evan You) - Vue.js的發起人 - 理念:做得好可以徹底解決改一行代碼等半天熱更新的問題。 - [vite github](https://github.com/vitejs/vite) ## 理解 vite 運作原理 - 瀏覽器請求的 response 直接編譯,跳過打包。有益於原本 webpack 專案每次修改就要打包重啟 web server 的作法,可以加快開發速度。 - 用 vite 改寫的專案,原本要打包 4 秒,可以縮短到 1 秒。 - [twitter 大大的比較](https://twitter.com/i/status/1282727239230996480) - webpack v.s. vite: - webpack 要經過編譯、打包、run server - vite 不進行編譯、打包,直接 run server,它會即時編譯,只編譯**需要的部分**。(只編譯當前使用的 component) - 與 vite 類似的原理 [Snowpack](https://www.snowpack.dev/) ![Unbundled development](https://www.snowpack.dev/img/snowpack-unbundled-example-3.png) ## 剖析 vite 部分原始碼 ### 透過瀏覽器觀察 vite 行為 - 因為沒有編譯、打包,所以會在 Request 發現許多請求,跟 webpack 的差異在於,webpack 打包好給瀏覽器用。而 vite 透過轉換成相對路徑,透過 es module 語法引入 module。 - 會即時用 WebSocket 更新變更的 component。 [ES modules: A cartoon deep-dive](https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/) ### 原生 ES Module 標準 `<script src="main.js" type="module"></script>` 必須是絕對或是相對路徑,才能讀取到該 module。 - [瀏覽器支援度](https://caniuse.com/?search=javascript%20modules): ![](https://i.imgur.com/KIIdN0T.png) > 但 vite 是開發過程的輔助工具,開發時沒有使用不支援的瀏覽器就不需要太過擔心瀏覽器支援程度。 ### vite 開發時所使用的套件 - Native ES Module - [koa](https://koajs.com/) - [chokidar](https://github.com/paulmillr/chokidar) - [esbuild](https://github.com/evanw/esbuild) - [rollup.js](https://github.com/rollup/rollup) - @vue/compiler-sfc(optional) ### 工具內部構造、原始碼語法特色 - 由於不進行再編譯,故透過 WebSocket 的推送進行元件更新。 - 在模組相依部分,其實還是有做轉譯及編譯的動作。 - 預設不編譯,可以在 run serve 指令時用 `--force` option 強迫編譯。 - optimize 本身有 cache 機制,故可以用 `--force` 繞過 cache 。 ## 與現行主流工具的差異對比 - 預設產生的request較多 - 可以透過升級成 HTTP2 來解決問題。 ## 總結 - vite 解決什麼問題? - vite 用來提高開發體驗 - vite 只能用在 vue 上面嗎? - 不只用在 vue 上面,twitter 的例子也有用在 react 上面。 - Vue Cli/ webpack 會被vite取代嗎? - 不是用來取代,而是增加開發選項 - vite 可以用在正式專案上嗎? - 實驗、小型專案推薦使用 - 大包、從 webpack轉的不推薦(之前的外掛不能用) [awesome-vite.js 是可參考的專案](https://github.com/vitejs/awesome-vite) # 聊天區 <!-- 我都念vite --> 窩不知道要唸 vite,連主持人都唸錯,窩怎麼可能唸對 ![](https://i.imgur.com/QBMwXMS.png =200x) <!-- wwwwwww --> 辣個瀏覽器,為了你,總是擋在最前面(講者對IE的吐嘲) ![Internet Explorer is the best browser to download others with](https://i.imgur.com/KjA2G1u.png =200x) ###### tags: `MOPCON 2020`

    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