mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-06 21:03:47 +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
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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue