Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit c866856

Browse files
committed
fix(docz-core): serve static files from public
1 parent b1c87b5 commit c866856

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

packages/docz-core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"koa": "^2.5.2",
5555
"koa-connect": "^2.0.1",
5656
"koa-mount": "^3.0.0",
57+
"koa-range": "^0.3.0",
5758
"koa-static": "^5.0.0",
5859
"load-cfg": "^0.5.9",
5960
"lodash.get": "^4.4.2",

packages/docz-core/src/Entries.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ const fromTemplates = (file: string) => path.join(paths.templates, file)
1515
const getHtmlFilepath = (indexHtml: string | undefined) =>
1616
indexHtml ? path.join(paths.root, indexHtml) : fromTemplates('index.tpl.html')
1717

18+
const getPublicUrl = (config: Config, dev: boolean): string => {
19+
const prefix = config.base === '/' ? '' : config.base
20+
return dev ? prefix : `${prefix}/public`
21+
}
22+
1823
const writeAppFiles = async (config: Config, dev: boolean): Promise<void> => {
1924
const { plugins, title, description, theme, indexHtml } = config
2025
const props = Plugin.propsOfPlugins(plugins)
@@ -42,6 +47,7 @@ const writeAppFiles = async (config: Config, dev: boolean): Promise<void> => {
4247
const rawIndexHtml = html({
4348
title,
4449
description,
50+
publicUrl: getPublicUrl(config, dev),
4551
})
4652

4753
await touch(paths.rootJs, rawRootJs)

packages/docz-core/src/bundlers/webpack/devserver.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import * as path from 'path'
2+
import * as fs from 'fs-extra'
23
import * as Koa from 'koa'
34
import { Configuration } from 'webpack'
5+
import mount from 'koa-mount'
6+
import range from 'koa-range'
47
import convert from 'koa-connect'
8+
import serveStatic from 'koa-static'
59
import history from 'connect-history-api-fallback'
610
import serveWaitpage from 'webpack-serve-waitpage'
711

12+
import * as paths from '../../config/paths'
813
import { Config } from '../../commands/args'
914
import { ServerHooks } from '../../Bundler'
1015

@@ -33,6 +38,12 @@ export const devServerConfig = (
3338
middleware.webpack()
3439
middleware.content()
3540

41+
app.use(range)
42+
43+
if (fs.existsSync(paths.appPublic)) {
44+
app.use(mount(args.base, serveStatic(paths.appPublic)))
45+
}
46+
3647
app.use(
3748
convert(
3849
history({

packages/docz-core/src/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ declare module 'webpackbar'
3232
declare module 'webpack-serve'
3333
declare module 'webpack-serve-waitpage'
3434
declare module 'koa-mount'
35+
declare module 'koa-range'
3536
declare module 'koa-connect'
3637
declare module 'koa-static'
3738
declare module 'detect-port'

yarn.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6992,6 +6992,12 @@ koa-mount@^3.0.0:
69926992
debug "^2.6.1"
69936993
koa-compose "^3.2.1"
69946994

6995+
koa-range@^0.3.0:
6996+
version "0.3.0"
6997+
resolved "https://registry.npmjs.org/koa-range/-/koa-range-0.3.0.tgz#3588e3496473a839a1bd264d2a42b1d85bd7feac"
6998+
dependencies:
6999+
stream-slice "^0.1.2"
7000+
69957001
koa-send@^5.0.0:
69967002
version "5.0.0"
69977003
resolved "https://registry.npmjs.org/koa-send/-/koa-send-5.0.0.tgz#5e8441e07ef55737734d7ced25b842e50646e7eb"
@@ -10891,6 +10897,10 @@ stream-shift@^1.0.0:
1089110897
version "1.0.0"
1089210898
resolved "https://registry.npmjs.org/stream-shift/-/stream-shift-1.0.0.tgz#d5c752825e5367e786f78e18e445ea223a155952"
1089310899

10900+
stream-slice@^0.1.2:
10901+
version "0.1.2"
10902+
resolved "https://registry.npmjs.org/stream-slice/-/stream-slice-0.1.2.tgz#2dc4f4e1b936fb13f3eb39a2def1932798d07a4b"
10903+
1089410904
string-argv@^0.0.2:
1089510905
version "0.0.2"
1089610906
resolved "https://registry.npmjs.org/string-argv/-/string-argv-0.0.2.tgz#dac30408690c21f3c3630a3ff3a05877bdcbd736"

0 commit comments

Comments
 (0)