Skip to content

Commit

Permalink
修改引用方式,增加SAMPLE
Browse files Browse the repository at this point in the history
  • Loading branch information
easonyq committed Sep 8, 2017
1 parent 73db82d commit d360323
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 73 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ crater 会根据根目录下的 `product` 目录中的配置文件生成一份 `

## 使用方式

开发者将代码 clone 到本地后有 ____ 个步骤需要进行
开发者将代码 clone 到本地后有三个步骤需要进行

### 编写配置文件

Expand Down
2 changes: 1 addition & 1 deletion build/webpack.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = {
['serviceworker-cache-polyfill', resolve('main.js')],
output: {
path: config.build.outputPath,
filename: isTest ? 'service-worker.js' : 'service-worker-[hash:8].js'
filename: isTest ? 'service-worker.js' : 'service-worker.js'
},
devtool: config.build.productionSourceMap ? '#source-map' : false,
module: {
Expand Down
8 changes: 7 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
'use strict';

import sw from './lib/sw-base';
import product from './product';

function requireAll(requireContext) {
return requireContext.keys().map(requireContext);
}

// import product/*
const product = requireAll(require.context('./product', true, /^\.\/.*\.js$/));

/**
* 获取缓存名称
Expand Down
63 changes: 63 additions & 0 deletions product/SAMPLE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Product Sample

You should list all configures of your products here, including __WHAT__ resources should be cached in __WHICH__ strategy. Sample config files are as follows:

## Sample 1: pageSearch.conf.js

```javascript

'use strict';

export default {

name: 'pageSearch',

// referrer url patterns
referrerPattern: /\/s\?/,

validateReferrer: 'https://m.baidu.com/s?word=123&ts=0&t_kt=0&ie=utf-8&rsv_iqid=2950933944&rsv_t=59feNNSsxLiVpQVUwj7SxdZ%252BTEvttKzgZj7zBw%252BUz%252FRihNQcWwKR&sa=ib&rsv_pq=2950933944',

routers: [
{
method: 'get',
// static file url patterns
urlPattern: /se\/static\/(js|pmd|css)\/.*(css|js)$/,
strategy: 'networkFirst',
validate: [{
url: '/se/static/js/uiamd/bdbox/follow_4ff41a2.js'
}]
}
]
};

```

## Sample 2: superFrame.conf.js

```javascript

'use strict';

export default {

name: 'superFrame',

// referrer url patterns
referrerPattern: /\/sf\?/,

validateReferrer: 'https://m.baidu.com/sf?openapi=1&dspName=iphone&from_sf=1&pd=city&resource_id=4324&ms=1&ms=1&word=%E5%8C%97%E4%BA%AC&hide=1&apitn=tangram&top=%7B%22sfhs%22%3A2%7D&city_name=None&title=%E5%8C%97%E4%BA%AC%E6%97%85%E6%B8%B8&lid=4572408700669128688&frsrcid=32228&frorder=1',

routers: [
{
method: 'get',
// static file url patterns
urlPattern: /se\/static\/sf\/.*(css|js)$/,
strategy: 'networkFirst',
validate: [{
url: '/se/static/sf/app/pmd/pmd/deps/naboo_eaee39f.js'
}]
}
]
};

```
14 changes: 0 additions & 14 deletions product/index.js

This file was deleted.

28 changes: 0 additions & 28 deletions product/pageSearch.conf.js

This file was deleted.

28 changes: 0 additions & 28 deletions product/superFrame.conf.js

This file was deleted.

0 comments on commit d360323

Please sign in to comment.