mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-28 22:18:44 +02:00
chore: remove noWatch cli options because you cant disable watch in wds (#1480)
This commit is contained in:
parent
05ba7d835d
commit
1ec4a9f999
3 changed files with 27 additions and 37 deletions
|
@ -80,17 +80,15 @@ program
|
|||
.description('Start development server')
|
||||
.option('-p, --port <port>', 'use specified port (default: 3000)')
|
||||
.option('-h, --host <host>', 'use specified host (default: localhost')
|
||||
.option('-nw, --no-watch <noWatch>', 'disable live reload (default: false)')
|
||||
.option(
|
||||
'--hot-only',
|
||||
'Do not fallback to page refresh if hot reload fails (default: false)',
|
||||
)
|
||||
.option('--no-cache-loader', 'Do not use cache-loader')
|
||||
.action((siteDir = '.', {port, host, noWatch, hotOnly, cacheLoader}) => {
|
||||
.action((siteDir = '.', {port, host, hotOnly, cacheLoader}) => {
|
||||
wrapCommand(start)(path.resolve(siteDir), {
|
||||
port,
|
||||
host,
|
||||
noWatch,
|
||||
hotOnly,
|
||||
cacheLoader,
|
||||
});
|
||||
|
|
|
@ -41,36 +41,32 @@ module.exports = async function start(siteDir, cliOptions = {}) {
|
|||
const props = await load(siteDir, cliOptions);
|
||||
|
||||
// Reload files processing.
|
||||
if (!cliOptions.noWatch) {
|
||||
const reload = () => {
|
||||
load(siteDir).catch(err => {
|
||||
console.error(chalk.red(err.stack));
|
||||
});
|
||||
};
|
||||
const {plugins} = props;
|
||||
|
||||
const normalizeToSiteDir = filepath => {
|
||||
if (filepath && path.isAbsolute(filepath)) {
|
||||
return path.relative(siteDir, filepath);
|
||||
}
|
||||
return filepath;
|
||||
};
|
||||
|
||||
const pluginPaths = _.compact(
|
||||
_.flatten(
|
||||
plugins.map(
|
||||
plugin => plugin.getPathsToWatch && plugin.getPathsToWatch(),
|
||||
),
|
||||
),
|
||||
).map(normalizeToSiteDir);
|
||||
const fsWatcher = chokidar.watch([...pluginPaths, CONFIG_FILE_NAME], {
|
||||
cwd: siteDir,
|
||||
ignoreInitial: true,
|
||||
const reload = () => {
|
||||
load(siteDir).catch(err => {
|
||||
console.error(chalk.red(err.stack));
|
||||
});
|
||||
['add', 'change', 'unlink', 'addDir', 'unlinkDir'].forEach(event =>
|
||||
fsWatcher.on(event, reload),
|
||||
);
|
||||
}
|
||||
};
|
||||
const {siteConfig, plugins = []} = props;
|
||||
|
||||
const normalizeToSiteDir = filepath => {
|
||||
if (filepath && path.isAbsolute(filepath)) {
|
||||
return path.relative(siteDir, filepath);
|
||||
}
|
||||
return filepath;
|
||||
};
|
||||
|
||||
const pluginPaths = _.compact(
|
||||
_.flatten(
|
||||
plugins.map(plugin => plugin.getPathsToWatch && plugin.getPathsToWatch()),
|
||||
),
|
||||
).map(normalizeToSiteDir);
|
||||
const fsWatcher = chokidar.watch([...pluginPaths, CONFIG_FILE_NAME], {
|
||||
cwd: siteDir,
|
||||
ignoreInitial: true,
|
||||
});
|
||||
['add', 'change', 'unlink', 'addDir', 'unlinkDir'].forEach(event =>
|
||||
fsWatcher.on(event, reload),
|
||||
);
|
||||
|
||||
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
|
||||
const port = await getPort(cliOptions.port);
|
||||
|
@ -79,7 +75,6 @@ module.exports = async function start(siteDir, cliOptions = {}) {
|
|||
const urls = prepareUrls(protocol, host, port);
|
||||
const openUrl = normalizeUrl([urls.localUrlForBrowser, baseUrl]);
|
||||
|
||||
const {siteConfig, plugins = []} = props;
|
||||
let config = merge(createClientConfig(props), {
|
||||
plugins: [
|
||||
// Generates an `index.html` file with the <script> injected.
|
||||
|
@ -115,12 +110,10 @@ module.exports = async function start(siteDir, cliOptions = {}) {
|
|||
compress: true,
|
||||
clientLogLevel: 'error',
|
||||
hot: true,
|
||||
// Do not fallback to page refresh if hot reload fails
|
||||
// https://webpack.js.org/configuration/dev-server/#devserverhotonly
|
||||
hotOnly: cliOptions.hotOnly,
|
||||
quiet: true,
|
||||
headers: {
|
||||
'access-control-allow-origin': '*', // Needed for CORS.
|
||||
'access-control-allow-origin': '*',
|
||||
},
|
||||
publicPath: baseUrl,
|
||||
watchOptions: {
|
||||
|
|
|
@ -47,7 +47,6 @@ Builds and serves the static site with [Webpack Dev Server](https://webpack.js.o
|
|||
|-|-|-|
|
||||
|`--port`|`3000`|Specifies the port of the dev server|
|
||||
|`--host`|`localhost`|Specifie a host to use. E.g., if you want your server to be accessible externally, you can use `--host 0.0.0.0`|
|
||||
|`--no-watch`|`false`|<!-- TODO problematic atm --> Disables watching files for hot reload|
|
||||
|`--hot-only`|`false`|Enables Hot Module Replacement without page refresh as fallback in case of build failures. More information [here](https://webpack.js.org/configuration/dev-server/#devserverhotonly).|
|
||||
|
||||
### `docusaurus build`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue