Skip to content

Commit

Permalink
chore: remove noWatch cli options because you cant disable watch in wds
Browse files Browse the repository at this point in the history
  • Loading branch information
endiliey committed May 17, 2019
1 parent 05ba7d8 commit 484d988
Show file tree
Hide file tree
Showing 4 changed files with 221 additions and 67 deletions.
4 changes: 1 addition & 3 deletions packages/docusaurus/bin/docusaurus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
57 changes: 25 additions & 32 deletions packages/docusaurus/src/commands/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 reload = () => {
load(siteDir).catch(err => {
console.error(chalk.red(err.stack));
});
};
const {siteConfig, plugins = []} = props;

const normalizeToSiteDir = filepath => {
if (filepath && path.isAbsolute(filepath)) {
return path.relative(siteDir, filepath);
}
return filepath;
};
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 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);
Expand All @@ -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.
Expand Down Expand Up @@ -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: {
Expand Down
1 change: 0 additions & 1 deletion website/docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
Loading

0 comments on commit 484d988

Please sign in to comment.