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

Display network address - tone down Webpack output #1397

Merged
merged 2 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions packages/cli/src/get-network-address.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {networkInterfaces} from 'os';

export const getNetworkAddress = (): string | undefined => {
for (const interfaceDetails of Object.values(networkInterfaces())) {
if (!interfaceDetails) continue;

for (const details of interfaceDetails) {
const {address, family, internal} = details;

if (family === 'IPv4' && !internal) return address;
}
}
};
23 changes: 18 additions & 5 deletions packages/cli/src/preview-server/dev-middleware/setup-hooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {webpack} from '@remotion/bundler';
import {Log} from '../../log';
import {truthy} from '../../truthy';
import {isColorSupported} from './is-color-supported';
import type {DevMiddlewareContext} from './types';

Expand All @@ -25,16 +26,28 @@ export function setupHooks(context: DevMiddlewareContext) {

logger.log('Compilation finished');

const statsOptions = {
preset: 'normal',
const statsOptions: webpack.Configuration['stats'] = {
preset: 'errors-warnings',
colors: isColorSupported,
};

const printedStats = stats.toString(statsOptions);

// Avoid extra empty line when `stats: 'none'`
if (printedStats) {
Log.info(printedStats);
const lines = printedStats
.split('\n')
.map((a) => a.trimEnd())
.filter(truthy)
.map((a) => {
if (a.startsWith('webpack compiled')) {
return `Built in ${stats.endTime - stats.startTime}ms`;
}

return a;
})
.join('\n');

if (lines) {
Log.info(lines);
}

context.callbacks = [];
Expand Down
13 changes: 3 additions & 10 deletions packages/cli/src/preview-server/hot-middleware/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@ import type {webpack} from '@remotion/bundler';
import type {IncomingMessage, ServerResponse} from 'http';
import {parse} from 'url';
import {Log} from '../../log';
import type {
HotMiddlewareMessage,
ModuleMap,
WebpackStats} from './types';
import {
hotMiddlewareOptions
} from './types';
import type {HotMiddlewareMessage, ModuleMap, WebpackStats} from './types';
import {hotMiddlewareOptions} from './types';

const pathMatch = function (url: string, path: string) {
try {
Expand All @@ -35,7 +30,7 @@ export const webpackHotMiddleware = (compiler: webpack.Compiler) => {

function onInvalid() {
latestStats = null;
Log.info('webpack building...');
Log.info('Building...');
eventStream?.publish({
action: 'building',
});
Expand Down Expand Up @@ -143,8 +138,6 @@ function publishStats(
name = statsResult.compilation.name || '';
}

Log.info(`webpack built in ${_stats.time}ms`);

eventStream?.publish({
name,
action,
Expand Down
14 changes: 13 additions & 1 deletion packages/cli/src/preview.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import betterOpn from 'better-opn';
import path from 'path';
import {chalk} from './chalk';
import {ConfigInternals} from './config';
import {getEnvironmentVariables} from './get-env';
import {getInputProps} from './get-input-props';
import {getNetworkAddress} from './get-network-address';
import {Log} from './log';
import {parsedCli} from './parse-command-line';
import type {LiveEventsServer} from './preview-server/live-events';
Expand Down Expand Up @@ -83,7 +85,17 @@ export const previewCommand = async (remotionRoot: string) => {
);

setLiveEventsListener(liveEventsServer);
Log.info(`Server running on http://localhost:${port}`);
const networkAddress = getNetworkAddress();
if (networkAddress) {
Log.info(
`Server ready - Local: ${chalk.underline(
`http://localhost:${port}`
)}, Network: ${chalk.underline(`http://${networkAddress}:${port}`)}`
);
} else {
Log.info(`Running on http://localhost:${port}`);
}

betterOpn(`http://localhost:${port}`);
await new Promise(noop);
};