Skip to content

Commit

Permalink
feat: 支持静态文件目录
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongzhi107 committed Dec 3, 2019
1 parent ef5a380 commit d2ec849
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/runtime/utils/addRoutes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { existsSync } from 'fs';

export default (app) => {
if (process.env.DACE_PATH_ROUTES && existsSync(process.env.DACE_PATH_ROUTES)) {
const router = require(process.env.DACE_PATH_ROUTES);
app.use(router);
}
};
14 changes: 12 additions & 2 deletions src/runtime/utils/addStatic.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import { existsSync } from 'fs';
import express from 'express';

export default (app) => {
const {
DACE_PATH_STATIC,
DACE_PUBLIC_PATH,
DACE_PATH_CLIENT_DIST
} = process.env;
// 当 publicPath = '/' 需要将编译目录挂载为虚拟目录(本地开发模式)
if (process.env.DACE_PUBLIC_PATH === '/') {
app.use(express.static(process.env.DACE_PATH_CLIENT_DIST));
if (DACE_PUBLIC_PATH === '/') {
app.use(express.static(DACE_PATH_CLIENT_DIST));
}

if (DACE_PATH_STATIC !== '' && existsSync(DACE_PATH_STATIC)) {
app.use(express.static(DACE_PATH_STATIC));
}
};

0 comments on commit d2ec849

Please sign in to comment.