1 | // 此文件可或者 koa 中间件,所有 app 都会用到
|
2 | // 扩展时候需考虑普适性
|
3 |
|
4 | const path = require('path')
|
5 | const getDistPath = require('../utils/get-dist-path')
|
6 |
|
7 | module.exports = (server) => {
|
8 |
|
9 | /* 静态目录,用于外界访问打包好的静态文件js、css等 */
|
10 |
|
11 | const koaStatic = require('koa-static')
|
12 | const convert = require('koa-convert')
|
13 | // const rootPath = getCwd() + '/dist/public'
|
14 | const rootPath = path.resolve(getDistPath(), './public')
|
15 | const option = {
|
16 | maxage: 0,
|
17 | hidden: true,
|
18 | index: 'index.html',
|
19 | defer: false,
|
20 | gzip: true,
|
21 | extensions: false
|
22 | }
|
23 | server.app.use(convert(koaStatic(rootPath, option)))
|
24 | }
|