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

✨ add support for polling when watching file changes #184

Merged
merged 2 commits into from
May 22, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,25 @@ The compiler for our training material. Sensei is a replacement for
--workdir /$(basename $(pwd)) \
--publish ${SENSEI_PORT:-8080}:${SENSEI_PORT:-8080} \
--env SENSEI_PORT \
--env SENSEI_WATCH_POLL \
--cap-add=SYS_ADMIN \
zenika/sensei'
```

> ⚠ When running sensei inside a Docker container, the `--material` is limited
> to descendants of the working directory.

> ⚠ If sensei fails to recompile on changes, try setting `SENSEI_WATCH_POLL` to
> `true`.

> ⚠ To change `SENSEI_PORT` when using this alias, use the following syntax:
> `export SENSEI_PORT=9000; sensei`. See
> [here](https://github.com/Zenika/sensei/issues/147#issuecomment-1091188979).

#### Notes on running in Docker for Windows

> ℹ️ The following also applies to Colima on macOS.

When bind-mounting files in Docker for Windows with WSL2,
the [recommendation](https://docs.docker.com/desktop/windows/wsl/#best-practices)
is to store files in the Linux filesystem, i.e. inside WSL2.
Expand All @@ -42,7 +48,9 @@ to edit files on the Linux filesystem.

Therefore it is recommended to clone the training repository in the Linux filesystem then to run the alias from WSL2.

> ⚠ If you use the Windows filesystem, hot reload when changing training content won't work.
> ⚠ If you use the Windows filesystem, hot reload when changing training content
> won't work out-of-the-box, but you can set `SENSEI_WATCH_POLL` to `true` to
> enable it.

> ⚠ If you use the Windows filesystem and expect to use the alias within Git Bash for Windows, prepend the
> `--volume` and `--workdir` options with an additional slash
Expand Down
11 changes: 9 additions & 2 deletions src/build/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
const Prism = require("prismjs");
require("prismjs/components/")();

/**
*
* @param {*} env
* @param {*} argv
* @returns {import("webpack").Configuration}
*/
module.exports = (env = {}, argv = {}) => {
assertRequiredOptionsArePresent(env);

Expand Down Expand Up @@ -157,8 +163,9 @@ module.exports = (env = {}, argv = {}) => {
analyzerPort: env.bundleAnalyzer?.port,
}),
],
devServer: {
contentBase: false,
watchOptions: {
poll: env.watch?.poll,
aggregateTimeout: 300,
},
};
};
Expand Down
11 changes: 9 additions & 2 deletions src/cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ const webpackConfig = require("../build/webpack.config");
const webpack = require("webpack");
const yargs = require("yargs/yargs");

/**
*
* @param {*} args
* @param {ReturnType<typeof composeEnv>} env
*/
async function cli(args, env) {
const {
_: [command],
Expand All @@ -20,10 +25,10 @@ async function cli(args, env) {
`Processing folder '${options.material}' as '${options.slug}' using slide size ${options.slideWidth}x${options.slideHeight} and language '${options.language}'`
);

const { host, port, bundleAnalyzer } = env;
const { host, port, bundleAnalyzer, watch } = env;
switch (command) {
case "serve":
await serve({ ...options, bundleAnalyzer }, { host, port });
await serve({ ...options, bundleAnalyzer, watch }, { host, port });
break;
case "build":
await build({ ...options, bundleAnalyzer });
Expand Down Expand Up @@ -190,6 +195,7 @@ function composeEnv() {
SENSEI_BUNDLE_ANALYZER_MODE,
SENSEI_BUNDLE_ANALYZER_HOST,
SENSEI_BUNDLE_ANALYZER_PORT,
SENSEI_WATCH_POLL,
} = process.env;
const bundleAnalyzerExplicitlyEnabled =
SENSEI_BUNDLE_ANALYZER_ENABLED === "true";
Expand All @@ -210,6 +216,7 @@ function composeEnv() {
host: SENSEI_BUNDLE_ANALYZER_HOST,
port: SENSEI_BUNDLE_ANALYZER_PORT,
},
watch: { poll: SENSEI_WATCH_POLL === "true" },
};
}

Expand Down