项目作者: lijinke666

项目描述 :
:triangular_flag_on_post: webpack plugin - add static cache manifest file to your project
高级语言: JavaScript
项目地址: git://github.com/lijinke666/add-static-cache-webpack-plugin.git
创建时间: 2017-07-10T03:34:25Z
项目社区:https://github.com/lijinke666/add-static-cache-webpack-plugin

开源协议:MIT License

下载


add-static-cache-webpack-plugin

add static cache manifest file in yours project , webpack build after create HTML5 Cache Manifest File , add your css,image,fonts in this cahce file

Installation

  1. npm install add-static-cache-webpack-plugin --save-dev

How to Use ?

  • webpack.config.js
    ```javascript
    const AddStaticCachePlugin = require(‘add-static-cache-webpack-plugin’)

module.exports = {

plugins: [
new AddStaticCachePlugin({
tempalte:””, // Not required Default template See the instructions below
cacheName:”jinke.appcache”, // Not required Default app.appcache
comments:”I am commnets”, // Not required Default add static cache webpack plugin appCache
publicPath:”/“ // Not required Default create temp file in your webpack.config.js output options publicPath
})
]
};

  1. ### options
  2. ---
  3. - #### template
  4. - type : `String`
  5. - default : `{DEFAULT TEMP FILE}`
  6. - #### cacheName
  7. - type : `String`
  8. - default : `'app.appcache'`
  9. - #### comments
  10. - type : `String`
  11. - default : `'add static cache webpack plugin appCache'`
  12. - #### publicPath
  13. - type : `String`
  14. - default : ""
  15. ---
  16. ### DEFAULT TEMP FILE
  1. const defaultTpl = `
  2. CACHE MANIFEST
  3. # add static cache webpack plugin appCache
  4. # {date}
  5. {cssPath}
  6. {fontsPath}
  7. {imagesPath}
  8. {jsPath}
  9. NETWORK:
  10. *
  11. `
  1. ### temp placeholder
  2. - ##### {date}
  3. - ##### {cssPath}
  4. - ##### {jsPath}
  5. - ##### {fontsPath}
  6. - ##### {comments}
  7. ### if your want custom template like
  8. `mkdir my.tpl`

CACHE MANIFEST

{comments}

{date}

{cssPath}
{fontsPath}
{jsPath}
{imagesPath}

NETWORK:
*

FALLBACK

feestyle

/static/ /404.html

  1. #### Then
  2. ```javascript
  3. new AddStaticCachePlugin({
  4. tempalte:"./my.tpl", // Not required Default template See the instructions below
  5. cacheName:"demo.appcache", // Not required Default `app.appcache`
  6. comments:"I am commnets", // Not required Default `add static cache webpack plugin appCache`
  7. publicPath:"/static/" // Not required Default create temp file in your `webpack.config.js` `output options publicPath`
  8. })

It looks something like this after compilation

/static/demo.appcache

  1. CACHE MANIFEST
  2. # I an comments
  3. # 2017/7/10 16:40:00
  4. /static/css/app.e2bba250.css
  5. /static/js/app.746fs3.js
  6. /static/fonts/iconfont13955767.svg
  7. /static/fonts/iconfonta5689859.ttf
  8. /static/fonts/iconfont75dce69e.eot
  9. /static/fonts/iconfont57b7441e.woff
  10. /static/images/banner1942579a6.jpg
  11. /static/images/head_img_s09e1d321.jpg
  12. NETWORK:
  13. *
  14. FALLBACK
  15. # feeStyle
  16. /static/ /404.html

Then

Import him in your html file
If your use html-webpack-plugin You can omit this step It will be auto import :)
  1. <html lang="zh" manifest="/static/demo.appcache">
  2. ...
  3. </html>

F12 look Application => Cache => Application Cache
There should be your cache :)