Skip to content

🎥 Make videos programmatically with React

implement webpack polling

Jonny Burgerfaf9de0b9206
diff --git a/packages/bundler/src/bundle.ts b/packages/bundler/src/bundle.ts
index 0de96e0680..10a8771e8d 100644
--- a/packages/bundler/src/bundle.ts
+++ b/packages/bundler/src/bundle.ts
@@ -76,6 +76,7 @@ export const getConfig = ({
entryPoints: [],
remotionRoot: resolvedRemotionRoot,
keyboardShortcutsEnabled: false,
+ poll: null,
});
};
diff --git a/packages/bundler/src/webpack-config.ts b/packages/bundler/src/webpack-config.ts
index 7cb2177dc9..e64793d0c8 100644
--- a/packages/bundler/src/webpack-config.ts
+++ b/packages/bundler/src/webpack-config.ts
@@ -47,6 +47,7 @@ export const webpackConfig = ({
entryPoints,
remotionRoot,
keyboardShortcutsEnabled,
+ poll,
}: {
entry: string;
userDefinedComponent: string;
@@ -60,6 +61,7 @@ export const webpackConfig = ({
keyboardShortcutsEnabled: boolean;
entryPoints: string[];
remotionRoot: string;
+ poll: number | null;
}): [string, WebpackConfiguration] => {
const conf: webpack.Configuration = webpackOverride({
optimization: {
@@ -74,14 +76,12 @@ export const webpackConfig = ({
},
},
watchOptions: {
+ poll: poll ?? undefined,
aggregateTimeout: 0,
ignored: ['**/.git/**', '**/node_modules/**'],
},
- devtool:
- environment === 'development'
- ? 'cheap-module-source-map'
- : 'cheap-module-source-map',
+ devtool: 'cheap-module-source-map',
entry: [
// Fast Refresh must come first,
// because setup-environment imports ReactDOM.
diff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.ts
index 43b6a4175e..3af47d36d4 100644
--- a/packages/cli/src/config/index.ts
+++ b/packages/cli/src/config/index.ts
@@ -94,6 +94,10 @@ import {setQuality} from './quality';
import {setScale} from './scale';
import {setPuppeteerTimeout} from './timeout';
import {setWebpackCaching} from './webpack-caching';
+import {
+ getWebpackPolling,
+ setWebpackPollingInMilliseconds,
+} from './webpack-poll';
import {getWidth, overrideWidth} from './width';
export const Config: ConfigType = {
@@ -108,6 +112,7 @@ export const Config: ConfigType = {
setPort,
setPublicDir,
setEntryPoint,
+ setWebpackPollingInMilliseconds,
},
Log: {
setLevel: setLogLevel,
@@ -203,6 +208,7 @@ export const ConfigInternals = {
getCrfOrUndefined,
getEntryPoint,
getNumberOfGifLoops,
+ getWebpackPolling,
};
export const overrideRemotion = () => {
diff --git a/packages/cli/src/config/webpack-poll.ts b/packages/cli/src/config/webpack-poll.ts
new file mode 100644
index 0000000000..bbbf103937
--- /dev/null
+++ b/packages/cli/src/config/webpack-poll.ts
@@ -0,0 +1,19 @@
+const DEFAULT_WEBPACK_POLL = null;
+
+let webpackPolling: number | null = DEFAULT_WEBPACK_POLL;
+
+export const setWebpackPollingInMilliseconds = (interval: number | null) => {
+ if (typeof interval !== 'number' && interval !== null) {
+ throw new TypeError(
+ `Polling must be a number or null, got ${JSON.stringify(
+ interval
+ )} instead.`
+ );
+ }
+
+ webpackPolling = interval;
+};
+
+export const getWebpackPolling = () => {
+ return webpackPolling;
+};
diff --git a/packages/cli/src/parse-command-line.ts b/packages/cli/src/parse-command-line.ts
index 871503aa0b..347c0e101a 100644
--- a/packages/cli/src/parse-command-line.ts
+++ b/packages/cli/src/parse-command-line.ts
@@ -61,6 +61,7 @@ export type CommandLineOptions = {
['enforce-audio-track']: boolean;
gl: OpenGlRenderer;
['package-manager']: string;
+ ['webpack-poll']: number;
};
export const BooleanFlags = [
@@ -242,6 +243,10 @@ export const parseCommandLine = () => {
Config.Bundling.setPublicDir(parsedCli['public-dir']);
}
+ if (typeof parsedCli['webpack-poll'] !== 'undefined') {
+ Config.Bundling.setWebpackPollingInMilliseconds(parsedCli['webpack-poll']);
+ }
+
if (typeof parsedCli['audio-bitrate'] !== 'undefined') {
Config.Output.setAudioBitrate(parsedCli['audio-bitrate']);
}
diff --git a/packages/cli/src/preview-server/start-server.ts b/packages/cli/src/preview-server/start-server.ts
index b35fdb45be..f4e3362a7f 100644
--- a/packages/cli/src/preview-server/start-server.ts
+++ b/packages/cli/src/preview-server/start-server.ts
@@ -27,6 +27,7 @@ export const startServer = async (
remotionRoot: string;
keyboardShortcutsEnabled: boolean;
userPassedPublicDir: string | null;
+ poll: number | null;
}
): Promise<{
port: number;
@@ -51,6 +52,7 @@ export const startServer = async (
],
remotionRoot: options.remotionRoot,
keyboardShortcutsEnabled: options.keyboardShortcutsEnabled,
+ poll: options.poll,
});
const compiler = webpack(config);
diff --git a/packages/cli/src/preview.ts b/packages/cli/src/preview.ts
index 6ef94e1495..d6e4cff59f 100644
--- a/packages/cli/src/preview.ts
+++ b/packages/cli/src/preview.ts
@@ -84,6 +84,7 @@ export const previewCommand = async (remotionRoot: string, args: string[]) => {
keyboardShortcutsEnabled: ConfigInternals.getKeyboardShortcutsEnabled(),
userPassedPublicDir: ConfigInternals.getPublicDir(),
webpackOverride: ConfigInternals.getWebpackOverrideFn(),
+ poll: ConfigInternals.getWebpackPolling(),
}
);
diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts
index 9bc048b44f..18b998a04b 100644
--- a/packages/core/src/config.ts
+++ b/packages/core/src/config.ts
@@ -77,6 +77,11 @@ export type ConfigType = {
* You can set an absolute path or a relative path that will be resolved from the closest package.json location.
*/
readonly setPublicDir: (publicDir: string | null) => void;
+ /**
+ * Enable Webpack polling instead of file system listeners for hot reloading in the preview.
+ * This is useful if you are using a remote directory or a virtual machine.
+ */
+ readonly setWebpackPollingInMilliseconds: (interval: number | null) => void;
};
readonly Log: {
/**