Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: some improvements for webpack-dev-server #5815

Merged
merged 2 commits into from Oct 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 10 additions & 8 deletions packages/docusaurus/src/commands/start.ts
Expand Up @@ -109,13 +109,16 @@ export default async function start(
}),
];

const fsWatcher = chokidar.watch(pathsToWatch, {
cwd: siteDir,
ignoreInitial: true,
const pollingOptions = {
usePolling: !!cliOptions.poll,
interval: Number.isInteger(cliOptions.poll)
? (cliOptions.poll as number)
: undefined,
};
const fsWatcher = chokidar.watch(pathsToWatch, {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

watch accepts chokidar options, and it seems to make sense to pass interval in addition to usePolling.

cwd: siteDir,
ignoreInitial: true,
...{pollingOptions},
});

['add', 'change', 'unlink', 'addDir', 'unlinkDir'].forEach((event) =>
Expand Down Expand Up @@ -166,8 +169,8 @@ export default async function start(

// https://webpack.js.org/configuration/dev-server
const devServerConfig: WebpackDevServer.Configuration = {
compress: true,
hot: cliOptions.hotOnly ? 'only' : true,
liveReload: false,
Copy link
Contributor Author

@lex111 lex111 Oct 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We always use hot, so liveReload is useless, so maybe it make sense to disable it explicitly?

client: {
progress: true,
overlay: {
Expand All @@ -182,17 +185,16 @@ export default async function start(
devMiddleware: {
publicPath: baseUrl,
// Reduce log verbosity, see https://github.com/facebook/docusaurus/pull/5420#issuecomment-906613105
stats: 'errors-warnings',
stats: 'summary',
Copy link
Contributor Author

@lex111 lex111 Oct 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should use "stats" because the current value duplicates the output in case of error:

Before
SyntaxError: /website/docs/blog.mdx: Expected corresponding JSX closing tag for <MDXLayout>. (14:0)
  12 | <p>{`sdfsds`}</p>
  13 | <p>{`sdfsd`}</p>
> 14 | </>
     | ^
  15 | <p>{`The blog feature enables you to deploy in no time a full-featured blog.`}</p>
  16 | <div {...{"className":"admonition admonition-info alert alert--info"}}><div parentName="div" {...{"className":"admonition-heading"}}><h5 parentName="div"><span parentName="h5" {...{"className":"admonition-icon"}}><svg parentName="span" {...{"xmlns":"http://www.w3.org/2000/svg","width":"14","height":"16","viewBox":"0 0 14 16"}}><path parentName="svg" {...{"fillRule":"evenodd","d":"M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"}}></path></svg></span>{`info`}</h5></div><div parentName="div" {...{"className":"admonition-content"}}><p parentName="div">{`Check the `}<a parentName="p" {...{"href":"/docs/api/plugins/@docusaurus/plugin-content-blog"}}>{`Blog Plugin API Reference documentation`}</a>{` for an exhaustive list of options.`}</p></div></div>
  17 | <h2 {...{"id":"initial-setup"}}>{`Initial setup`}</h2>
ERROR in ./docs/blog.mdx
Module build failed (from ../packages/docusaurus-mdx-loader/lib/index.js):
SyntaxError: /website/docs/blog.mdx: Expected corresponding JSX closing tag for <MDXLayout>. (14:0)

12 | <p>{sdfsds}</p>
13 | <p>{sdfsd}</p>
> 14 | </>
| ^
15 | <p>{The blog feature enables you to deploy in no time a full-featured blog.}</p>
16 | <div {...{"className":"admonition admonition-info alert alert--info"}}><div parentName="div" {...{"className":"admonition-heading"}}><h5 parentName="div"><span parentName="h5" {...{"className":"admonition-icon"}}><svg parentName="span" {...{"xmlns":"http://www.w3.org/2000/svg&quot;,&quot;width&quot;:&quot;14&quot;,&quot;height&quot;:&quot;16&quot;,&quot;viewBox&quot;:&quot;0 0 14 16"}}><path parentName="svg" {...{"fillRule":"evenodd","d":"M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"}}></path></svg></span>{info}</h5></div><div parentName="div" {...{"className":"admonition-content"}}><p parentName="div">{Check the }<a parentName="p" {...{"href":"/docs/api/plugins/@docusaurus/plugin-content-blog"}}>{Blog Plugin API Reference documentation}</a>{ for an exhaustive list of options.}</p></div></div>
17 | <h2 {...{"id":"initial-setup"}}>{Initial setup}</h2>
at Object._raise (/node_modules/@babel/parser/lib/index.js:510:17)
at Object.raiseWithData (/node_modules/@babel/parser/lib/index.js:503:17)
at Object.raise (/node_modules/@babel/parser/lib/index.js:464:17)
at Object.jsxParseElementAt (/node_modules/@babel/parser/lib/index.js:7219:14)
at Object.jsxParseElement (/node_modules/@babel/parser/lib/index.js:7248:17)
at Object.parseExprAtom (/node_modules/@babel/parser/lib/index.js:7255:19)
at Object.parseExprSubscripts (/node_modules/@babel/parser/lib/index.js:11217:23)
at Object.parseUpdate (/node_modules/@babel/parser/lib/index.js:11197:21)
at Object.parseMaybeUnary (/node_modules/@babel/parser/lib/index.js:11172:23)
at Object.parseMaybeUnaryOrPrivate (/node_modules/@babel/parser/lib/index.js:10986:59)
at Object.parseExprOps (/node_modules/@babel/parser/lib/index.js:10993:23)
at Object.parseMaybeConditional (/node_modules/@babel/parser/lib/index.js:10963:23)
at Object.parseMaybeAssign (/node_modules/@babel/parser/lib/index.js:10926:21)
at /node_modules/@babel/parser/lib/index.js:10888:39
at Object.allowInAnd (/node_modules/@babel/parser/lib/index.js:12720:12)
at Object.parseMaybeAssignAllowIn (/node_modules/@babel/parser/lib/index.js:10888:17)

client compiled with 1 error

After
SyntaxError: /home/lex/repos/docusaurus/website/docs/blog.mdx: Expected corresponding JSX closing tag for <MDXLayout>. (14:0)
  12 | <p>{`sdfsds`}</p>
  13 | <p>{`sdfsd`}</p>
> 14 | </>
     | ^
  15 | <p>{`The blog feature enables you to deploy in no time a full-featured blog.`}</p>
  16 | <div {...{"className":"admonition admonition-info alert alert--info"}}><div parentName="div" {...{"className":"admonition-heading"}}><h5 parentName="div"><span parentName="h5" {...{"className":"admonition-icon"}}><svg parentName="span" {...{"xmlns":"http://www.w3.org/2000/svg","width":"14","height":"16","viewBox":"0 0 14 16"}}><path parentName="svg" {...{"fillRule":"evenodd","d":"M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"}}></path></svg></span>{`info`}</h5></div><div parentName="div" {...{"className":"admonition-content"}}><p parentName="div">{`Check the `}<a parentName="p" {...{"href":"/docs/api/plugins/@docusaurus/plugin-content-blog"}}>{`Blog Plugin API Reference documentation`}</a>{` for an exhaustive list of options.`}</p></div></div>
  17 | <h2 {...{"id":"initial-setup"}}>{`Initial setup`}</h2>
client (webpack 5.60.0) compiled with 1 error

},
static: {
directory: path.resolve(siteDir, STATIC_DIR_NAME),
watch: {
usePolling: !!cliOptions.poll,

// Useful options for our own monorepo using symlinks!
// See https://github.com/webpack/webpack/issues/11612#issuecomment-879259806
followSymlinks: true,
ignored: /node_modules\/(?!@docusaurus)/,
...{pollingOptions},
},
},
historyApiFallback: {
Expand Down Expand Up @@ -233,7 +235,7 @@ export default async function start(

['SIGINT', 'SIGTERM'].forEach((sig) => {
process.on(sig, () => {
devServer.close();
devServer.stop();
process.exit();
});
});
Expand Down