Keaton 徽典
    • 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 No publishing access yet

      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.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      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
    • Make a copy
    • 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 Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy 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 No publishing access yet

    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.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    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
    # RL-08 前端打包/模組化/套件 ## 模組化方法(文章題目) 兩種輸出入方法 - CommonJS(主流) > export default name > import name from "aaaa" - AMD > var a = require("aaaa") > a() ## module 模組匯入匯出 ### package.json package.json 相當於 ruby 的 gem file 跑script下的命令。 ```json= "scripts": { "dev": "parcel src/index.html", "build": "parcel build src/index.html" } ``` **在終端機** * 用 yarn run dev 可以執行dev後面那段 ### JS的模組化 將相應功能分到不同JS檔案,相互import與export。 **main.js** * 測試印 console.log("hi") * 若無效,刪除parcel-cache與dist兩個資料夾。 **模組aaa.js** * 變成變數的都可以export * 三種export方法 * **export default** //預設匯出什麼 * **export { , }** //匯出複數的東西(函式、宣告後的常數都可以) * 直接在function前面接export(不建議) ![](https://i.imgur.com/9iP29QA.png) * 在另一個main.js可以匯入import進 > import hello from "./aaa.js" > hello () ```javascript= function hello() { console.log("hello") } function world() { console.log("world") } function hi() { console.log("hi") } // 下面沒寫 export there,所以 main.js 那邊收不到,只會收到有寫的 function there() { console.log("there") } // 讓aaa.js預設匯出 hello // 等等 import 的名字可隨意取,不管怎麼取名預設就是匯出 hello // 一個檔案只能有一個預設值 export default hello // 有寫 export 的才能匯出,import 名字要能搭得上 // there 相對來說是私有方法 // 除了{}寫法,也可以直接在 function 前面寫 export // 只要是變數都可以匯出,不一定要是 function export { world, hi } ``` **在網頁** 要引用模組的話,要指定型別為模組module > <script src="scripts/main.js" type="module"></script> **main.js** 就可以把aaa的內容import進來。像是 > import hello from "./aaa" > hello() ```javascript= import dayjs from "dayjs" const dd = dayjs("2018-08-08") console.log(dd.year()) console.log("hi") import hello from "./aaa.js" import aaa, { hi } from "./aaa.js" // 名字亂寫aaa也行,會輸入預設的(hello) hello() console.log(hi) console.log(aaa) import { createButton } from "./ui" const btn = createButton("hello") document.body.appendChild(btn) ``` **模組ui.js** 做一個按鈕,宣告function,建立元素 document.createElement 再匯出 export {createButton} ```javascript= // 用JS產生一個btn function createButton(wording) { const btn = document.createElement("button") btn.textContent = wording return btn } export default createButton ``` **main 再匯入** 加到body的最尾端appendChild 為什麼用const呼叫?因為原本模組內就這樣寫,守原來規則。 > import { createButton } from "./ui" > > const btn = createButton("hello") > document.body.appendChild(btn) ## 套件安裝 **npm install dayjs** = **yarn add dayjs** 兩個都可以安裝套件 yarn 可以一次下載多個,下載速度快(fb做的) **不要兩個混用**,兩個產生 package.lock 的方式不同,有可能會造成錯誤 - 參數: --save只用在目前專案,開發過程跟上線都會用到 --saveDev:上線之後用不到,不需要上線(ex:parcel) = -D 在package.js裡可看到安裝資訊,其中 * devDependencies 上線不需要 * dependencies 上線需要 安裝的套件會在node_moduel裡 ### Day.js [dayjs](https://www.npmjs.com/package/dayjs) 將字串=>時間的套件 * 安裝指令加參數 **--saveDev** 代表只在開發時用 * **安裝的套件會在node_moduel裡** * 進dayjs的package.js,可看到scripts設定等。 再讓main匯入 > import dayjs from "dayjs" 宣告為dd再印出 > const dd = dayjs("2018-08-08") > > console.log(dd.year()) > 或 > console.log(`${dd.day()}/${dd.month()}`) ### Tailwindcss 推薦用,慢慢變主流了 [tailwindcss](https://tailwindcss.com/docs/installation#installing-tailwind-css-as-a-post-css-plugin) - Tailwindui 收費的,用Tailwind幫你刻好很多東西 - tailwindui alternative => tailwindcomponent - codepen 有支援 tailwindcss 方便自己練習:可以點css做設定 [tailwindplay](https://play.tailwindcss.com/) :可試玩 #### 安裝 * bootstrap給你大框架,整組包好 * tailwind給你小零件,一堆小工具 * 安裝 > yarn add -D tailwindcss@latest postcss@latest autoprefixer@latest * 依照官方手冊 * 在根目錄建立 postcss.config.js ```javascript= module.exports = { plugins: { tailwindcss: {}, autoprefixer: {}, } } ``` * 官方cdn有**非同源錯誤NotSameOrigin**,改用cdnjs版本做(貼在head裡) * <link href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.8/tailwind.min.css" rel="stylesheet"> * **語法效果,可以直接實現RWD** ```htmlmixed= <h1 class="text-4xl md:text-6xl">Hello World??</h1> <a herf="#" class="bg-blue-300 px-4 py-3 rounded block w-16 text-white hover:text-red-400 hover:bg-blue-500">像是一個按鈕</a> ``` CodePen有直接支援。 #### @apply @apply 可以組合多個css,寫一個就好,類似 funciton 把要的東西都包好,方便使用。 例: 讓網頁裡的標籤寫 **class=list-item** 就好,不用像inline一樣長。 ```css= .list-item { @apply .py-1 .px-4 .font-light; } ``` * **TailwindUI** 可嘗試要收費 * 壓縮檔案,把不會用到的 css 去掉: 在 tailwind.config.js 檔案的 purge 檢查: purge: [ './src/**/*.html', './src/**/*.js', ] 可參考:[優化生產模式 ](https://tailwindcss.tw/docs/optimizing-for-production) ## 前端打包工具 ### parcel <=用這個 打包工具,輕鬆設定,對新手友善 可以把多個相同格式檔案打包成一個檔案 前例: * parcel src去讀index,會去讀一個main.js,連結到main.scss。 * 會後會打包成一個js。 ### webpack 打包工具,設定上有點麻煩 垃圾一個 ### electron 把 HTML CSS JS 打包成應用程式(如VSCode) 因為也把瀏覽器包進去所以很胖 ### esbuild 很快 ----- ## foreman 在本機用 開發過程才會用到 * 在Gemfile安裝foreman * 記得跑 bundle install ### 啟動 * 終端機 foreman s * 手動建立procfile 在根目錄,內容寫 > web: rails s -p 3000 > webpack: bin/webpack-dev-server 如此一來,啟動時2個一起開。 ###### tags: `Rails`

    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
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    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