chore: remove noWatch cli options because you cant disable watch in wds (#1480)

This commit is contained in:
Endi 2019-05-17 21:51:16 +07:00 committed by GitHub
parent 05ba7d835d
commit 1ec4a9f999
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 37 deletions

View file

@ -80,17 +80,15 @@ program
.description('Start development server') .description('Start development server')
.option('-p, --port <port>', 'use specified port (default: 3000)') .option('-p, --port <port>', 'use specified port (default: 3000)')
.option('-h, --host <host>', 'use specified host (default: localhost') .option('-h, --host <host>', 'use specified host (default: localhost')
.option('-nw, --no-watch <noWatch>', 'disable live reload (default: false)')
.option( .option(
'--hot-only', '--hot-only',
'Do not fallback to page refresh if hot reload fails (default: false)', 'Do not fallback to page refresh if hot reload fails (default: false)',
) )
.option('--no-cache-loader', 'Do not use cache-loader') .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), { wrapCommand(start)(path.resolve(siteDir), {
port, port,
host, host,
noWatch,
hotOnly, hotOnly,
cacheLoader, cacheLoader,
}); });

View file

@ -41,36 +41,32 @@ module.exports = async function start(siteDir, cliOptions = {}) {
const props = await load(siteDir, cliOptions); const props = await load(siteDir, cliOptions);
// Reload files processing. // Reload files processing.
if (!cliOptions.noWatch) { const reload = () => {
const reload = () => { load(siteDir).catch(err => {
load(siteDir).catch(err => { console.error(chalk.red(err.stack));
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,
}); });
['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 protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
const port = await getPort(cliOptions.port); const port = await getPort(cliOptions.port);
@ -79,7 +75,6 @@ module.exports = async function start(siteDir, cliOptions = {}) {
const urls = prepareUrls(protocol, host, port); const urls = prepareUrls(protocol, host, port);
const openUrl = normalizeUrl([urls.localUrlForBrowser, baseUrl]); const openUrl = normalizeUrl([urls.localUrlForBrowser, baseUrl]);
const {siteConfig, plugins = []} = props;
let config = merge(createClientConfig(props), { let config = merge(createClientConfig(props), {
plugins: [ plugins: [
// Generates an `index.html` file with the <script> injected. // Generates an `index.html` file with the <script> injected.
@ -115,12 +110,10 @@ module.exports = async function start(siteDir, cliOptions = {}) {
compress: true, compress: true,
clientLogLevel: 'error', clientLogLevel: 'error',
hot: true, hot: true,
// Do not fallback to page refresh if hot reload fails
// https://webpack.js.org/configuration/dev-server/#devserverhotonly
hotOnly: cliOptions.hotOnly, hotOnly: cliOptions.hotOnly,
quiet: true, quiet: true,
headers: { headers: {
'access-control-allow-origin': '*', // Needed for CORS. 'access-control-allow-origin': '*',
}, },
publicPath: baseUrl, publicPath: baseUrl,
watchOptions: { watchOptions: {

View file

@ -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| |`--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`| |`--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).| |`--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` ### `docusaurus build`