mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-22 13:37:05 +02:00
refactor: code
This commit is contained in:
parent
a9c3d50a68
commit
44122cd202
4 changed files with 37 additions and 48 deletions
|
@ -10,8 +10,6 @@ const serveStatic = require('koa-static');
|
|||
const history = require('connect-history-api-fallback');
|
||||
const portfinder = require('portfinder');
|
||||
const serve = require('webpack-serve');
|
||||
const webpackNiceLog = require('webpack-nicelog');
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
const load = require('../load');
|
||||
const createDevConfig = require('../webpack/dev');
|
||||
|
||||
|
@ -25,6 +23,7 @@ module.exports = async function start(siteDir, cliOptions = {}) {
|
|||
// Process all related files as a prop
|
||||
const props = await load(siteDir);
|
||||
|
||||
// Reload files processing
|
||||
if (!cliOptions.noWatch) {
|
||||
const reload = () => {
|
||||
load(siteDir).catch(err => {
|
||||
|
@ -49,43 +48,17 @@ module.exports = async function start(siteDir, cliOptions = {}) {
|
|||
const port = await getPort(cliOptions.port);
|
||||
const {baseUrl} = props;
|
||||
|
||||
// resolve webpack config
|
||||
let config = createDevConfig(props);
|
||||
config.plugin('WebpackNiceLog').use(webpackNiceLog, [
|
||||
{
|
||||
name: 'Munseo',
|
||||
onDone: () => {
|
||||
console.log(
|
||||
`\n${chalk.blue('Development server available at ')}${chalk.cyan(
|
||||
`http://localhost:${port}${baseUrl}`
|
||||
)}`
|
||||
);
|
||||
}
|
||||
}
|
||||
]);
|
||||
config.plugin('html-webpack-plugin').use(HtmlWebpackPlugin, [
|
||||
{
|
||||
inject: false,
|
||||
hash: true,
|
||||
template: path.resolve(__dirname, '../core/devTemplate.ejs'),
|
||||
filename: 'index.html',
|
||||
title: props.siteConfig.title
|
||||
}
|
||||
]);
|
||||
|
||||
// create compiler from generated webpack config
|
||||
config = config.toConfig();
|
||||
const config = createDevConfig(props).toConfig();
|
||||
const compiler = webpack(config);
|
||||
|
||||
// webpack-serve
|
||||
const nonExistentDir = path.resolve(__dirname, 'non-existent');
|
||||
setTimeout(async () => {
|
||||
await serve(
|
||||
{},
|
||||
{
|
||||
content: [nonExistentDir],
|
||||
compiler,
|
||||
open: false,
|
||||
open: true,
|
||||
devMiddleware: {
|
||||
logLevel: 'silent'
|
||||
},
|
||||
|
@ -96,11 +69,16 @@ module.exports = async function start(siteDir, cliOptions = {}) {
|
|||
logLevel: 'error',
|
||||
port,
|
||||
add: app => {
|
||||
// serve static files
|
||||
const staticDir = path.resolve(siteDir, 'static');
|
||||
if (fs.existsSync(staticDir)) {
|
||||
app.use(mount(baseUrl, serveStatic(staticDir)));
|
||||
}
|
||||
app.use(range); // enable range request https://tools.ietf.org/html/rfc7233
|
||||
|
||||
// enable HTTP range requests
|
||||
app.use(range);
|
||||
|
||||
// rewrite request to `/` since this is a SPA
|
||||
app.use(
|
||||
convert(
|
||||
history({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue