javck
    • 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 New
    • 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 Note Insights Versions and GitHub Sync 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
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- tags: laravel --- # Compiling Assets 如何將 js.css 等資源檔案打包成單一檔案 ![](https://i.imgur.com/UpSi17V.png) > 這一節說明如何將 js.css 等資源檔案打包成單一檔案,目的在於減少檔案的請求次數,以優化網頁效能。 > 相關資訊可以參考(https://laravel.com/docs/5.6/mix) Laravel Mix 提供了一個便利的API來定義網頁打包作業,讓你輕鬆的處理你的網頁應用裡所使用的網頁資源,如javascript和css。透過簡單的方法串連呼叫,你能夠流暢的定義你的資源處理流。 如下例所示: mix.js('resources/js/app.js', 'public/js').sass('resources/sass/app.scss', 'public/css'); 假如你曾經被Webpack和資源編譯給弄的頭昏腦脹,你將會愛上Laravel Mix。不過,你不需要在開發應用的時候去使用它。當然,你能夠自由的選用任何的資源處理流工具,甚至是完全不用。 ## 知識點 1.如何安裝? 在你觸發Mix之前,首先你需要有Node.js,並確認NPM有安裝在你的電腦上面。可以透過以下指令來檢查是否擁有... node -v npm -v 關於Node.js安裝,可以參考這個網頁(http://www.runoob.com/nodejs/nodejs-install-setup.html),官方下載安裝檔網址(https://nodejs.org/en/download/) 至於NPM,Node.js在v0.63版本之後就已經內建NPM了。 確保環境已經準備完成,最後剩下Laravel Mix的安裝。在一個新安裝的Laravel專案裡頭,你可以在根目錄找到一個package.json檔案。預設的package.json檔案包含了所有你需要的。就把它想成是composer.json檔案,除了它是定義Node依賴檔案而不是PHP。如需安裝依賴,你只需要開啟Terminal,在專案目錄執行以下指令: npm install ## 知識點 2.運行 Mix Mix是一個最高層的Webpack設定層,所以要跑你的Mix工作只需要去執行某一個被包含在預設Laravel裡的package.json檔內的NPM腳本 //執行所有Mix npm run dev //執行所有Mix並將輸入檔進行壓縮 npm run production //觀察資源檔的變化 npm run watch 以上指令將會不斷的在你的Terminal執行,並追蹤關聯檔案的變化。一旦出現改變,Webpack將會自動的重新編譯資源檔。 在某些環境,當關聯檔案變化卻不會自動編譯。在這個情況發生時,可以改用watch-poll命令。 npm run watch-poll ## 知識點 3.處理一般的樣式表 假如你想要把多個一般樣式表壓縮成單檔,你可以使用styles(),如下例所示將vendor資料夾的normalize.css和videojs.css壓縮後生成public/css/all.css。 //webpack.mix.js mix.styles([ 'public/css/vendor/normalize.css', 'public/css/vendor/videojs.css' ], 'public/css/all.css'); ## 知識點 4.處理一般的 js 檔案 假如你想要把多個js檔案壓縮成單檔,你可以使用scripts(),如下例所示將public/js資料夾的admin.js和dashboard.js壓縮後生成public/js/all.js。 //webpack.mix.js mix.scripts([ 'public/js/admin.js', 'public/js/dashboard.js' ], 'public/js/all.js'); ## 知識點 5.複製圖片或一般檔案 copy()用於複製檔案和資料夾到新的位置去。這在處理特定位於node_modules資料夾的資源,將之重新放至於public資料夾時非常有用。如下例: //webpack.mix.js mix.copy('node_modules/foo/bar.css', 'public/css/bar.css'); 當需要複製一個資料夾,copy()將會移除該資料夾的深層結構。如需保存其深層結構,只需要改用copyDirectory()即可,如下例: //webpack.mix.js mix.copyDirectory('resources/img', 'public/img'); ## 知識點 6.有辦法關掉 Mix 的 popup 通知嗎? 預設Mix會在打包完成之後在螢幕的右上方跳出一個popup視窗告訴你作業是否成功,如果需要關閉可以輸入以下程式: //webpack.mix.js mix.disableNotifications();

    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