mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-07 21:32:38 +02:00
feat: add koa-static to serve static files
This commit is contained in:
parent
c5dfddaf61
commit
0c69604fb2
4 changed files with 29 additions and 6 deletions
|
@ -9,4 +9,4 @@ Hi, Endilie here.
|
|||
|
||||
<!--truncate-->
|
||||
|
||||
Random thoughts, experiences, write-up of Endilie Yacop Sucipto will be shared here.
|
||||
Random tsasshoughts, experiences, write-up of Endilie Yacop Sucipto will be shared here.
|
||||
|
|
12
lib/dev.js
12
lib/dev.js
|
@ -5,6 +5,7 @@ const webpack = require('webpack');
|
|||
const chokidar = require('chokidar');
|
||||
const convert = require('koa-connect');
|
||||
const range = require('koa-range');
|
||||
const serveStatic = require('koa-static');
|
||||
const history = require('connect-history-api-fallback');
|
||||
const portfinder = require('portfinder');
|
||||
const serve = require('webpack-serve');
|
||||
|
@ -71,14 +72,15 @@ module.exports = async function dev(sourceDir, cliOptions = {}) {
|
|||
const compiler = webpack(config);
|
||||
|
||||
// webpack-serve
|
||||
const nonExistentDir = path.resolve(__dirname, 'non-existent')
|
||||
await serve(
|
||||
{},
|
||||
{
|
||||
content: [nonExistentDir],
|
||||
compiler,
|
||||
open: false, // don't open browser automatically
|
||||
open: true,
|
||||
devMiddleware: {
|
||||
logLevel: 'silent',
|
||||
publicPath
|
||||
logLevel: 'silent'
|
||||
},
|
||||
hotClient: {
|
||||
port: port + 1,
|
||||
|
@ -87,6 +89,10 @@ module.exports = async function dev(sourceDir, cliOptions = {}) {
|
|||
logLevel: 'error',
|
||||
port,
|
||||
add: app => {
|
||||
const staticDir = path.resolve(sourceDir, 'public');
|
||||
if (fs.existsSync(staticDir)) {
|
||||
app.use(mount(publicPath, serveStatic(staticDir)));
|
||||
}
|
||||
app.use(range); // enable range request https://tools.ietf.org/html/rfc7233
|
||||
app.use(
|
||||
convert(
|
||||
|
|
|
@ -53,6 +53,7 @@
|
|||
"html-webpack-plugin": "^3.2.0",
|
||||
"koa-connect": "^2.0.1",
|
||||
"koa-range": "^0.3.0",
|
||||
"koa-static": "^5.0.0",
|
||||
"portfinder": "^1.0.13",
|
||||
"react": "^16.4.1",
|
||||
"react-dom": "^16.4.1",
|
||||
|
|
20
yarn.lock
20
yarn.lock
|
@ -4014,6 +4014,22 @@ koa-range@^0.3.0:
|
|||
dependencies:
|
||||
stream-slice "^0.1.2"
|
||||
|
||||
koa-send@^5.0.0:
|
||||
version "5.0.0"
|
||||
resolved "https://registry.yarnpkg.com/koa-send/-/koa-send-5.0.0.tgz#5e8441e07ef55737734d7ced25b842e50646e7eb"
|
||||
dependencies:
|
||||
debug "^3.1.0"
|
||||
http-errors "^1.6.3"
|
||||
mz "^2.7.0"
|
||||
resolve-path "^1.4.0"
|
||||
|
||||
koa-static@^5.0.0:
|
||||
version "5.0.0"
|
||||
resolved "https://registry.yarnpkg.com/koa-static/-/koa-static-5.0.0.tgz#5e92fc96b537ad5219f425319c95b64772776943"
|
||||
dependencies:
|
||||
debug "^3.1.0"
|
||||
koa-send "^5.0.0"
|
||||
|
||||
koa-webpack@^5.1.0:
|
||||
version "5.1.0"
|
||||
resolved "https://registry.yarnpkg.com/koa-webpack/-/koa-webpack-5.1.0.tgz#7b9f04ea85c43c4d7ad845d0de01f0ed495eb5c0"
|
||||
|
@ -4474,7 +4490,7 @@ mute-stream@0.0.7:
|
|||
version "0.0.7"
|
||||
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab"
|
||||
|
||||
mz@^2.6.0:
|
||||
mz@^2.6.0, mz@^2.7.0:
|
||||
version "2.7.0"
|
||||
resolved "https://registry.yarnpkg.com/mz/-/mz-2.7.0.tgz#95008057a56cafadc2bc63dde7f9ff6955948e32"
|
||||
dependencies:
|
||||
|
@ -5597,7 +5613,7 @@ resolve-from@^3.0.0:
|
|||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-3.0.0.tgz#b22c7af7d9d6881bc8b6e653335eebcb0a188748"
|
||||
|
||||
resolve-path@^1.3.3:
|
||||
resolve-path@^1.3.3, resolve-path@^1.4.0:
|
||||
version "1.4.0"
|
||||
resolved "https://registry.yarnpkg.com/resolve-path/-/resolve-path-1.4.0.tgz#c4bda9f5efb2fce65247873ab36bb4d834fe16f7"
|
||||
dependencies:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue