log-viewer-webui: Add boilerplate React client.#468
Conversation
junhaoliao
left a comment
There was a problem hiding this comment.
In general it looks good to me. There are some devDependencies that are specified but I do not see the usages of those in the webpack config file. If those are to be configured later, can we submit those another PR?
| "lint:check": "npx eslint --no-eslintrc --config package.json src webpack.config.js", | ||
| "lint:fix": "npx eslint --fix --no-eslintrc --config package.json src webpack.config.js", | ||
| "build": "webpack --define-process-env-node-env production", | ||
| "watch": "webpack serve" |
There was a problem hiding this comment.
For consistency, can we rename this config as start? Let's continue the discussion in server/package.json.
| "dev": "NODE_ENV=development nodemon src/main.js", | ||
| "lint:check": "npx eslint --no-eslintrc --config package.json src", | ||
| "lint:fix": "npx eslint --fix --no-eslintrc --config package.json src", | ||
| "start": "NODE_ENV=production node src/main.js", |
There was a problem hiding this comment.
Would it be better to rename this script as prod and the one below for development as start? That way we will be consistently using start as the name for all development scripts across all repos.
| "@babel/preset-env": "^7.24.7", | ||
| "@babel/preset-react": "^7.24.7", | ||
| "@webpack-cli/generators": "^3.0.7", | ||
| "autoprefixer": "^10.4.19", |
There was a problem hiding this comment.
This seems handy, but it seems not only we need to configure "browserslist" in this package.json file but also we need to install postcss and add some related config in webpack.config.js according to their docs: https://github.com/postcss/autoprefixer#webpackhttps://github.com/postcss/autoprefixer#webpack
(Did I miss anything? )
There was a problem hiding this comment.
Sorry, I did have postcss initially, but had some issues so I removed it but forgot to remove this.
| "@babel/plugin-proposal-class-properties": "^7.18.6", | ||
| "@babel/plugin-transform-runtime": "^7.24.7", |
There was a problem hiding this comment.
I don't see those getting configured in webpack.config.js. Mind sharing what the usages are of those?
There was a problem hiding this comment.
Sorry, didn't clean up package.json properly.
| "@babel/plugin-transform-runtime": "^7.24.7", | ||
| "@babel/preset-env": "^7.24.7", | ||
| "@babel/preset-react": "^7.24.7", | ||
| "@webpack-cli/generators": "^3.0.7", |
There was a problem hiding this comment.
Maybe we just need "webpack-cli": "^5.1.4",?
| "eslint-config-yscope": "latest", | ||
| "html-webpack-plugin": "^5.6.0", | ||
| "mini-css-extract-plugin": "^2.9.0", | ||
| "prettier": "^3.3.2", |
There was a problem hiding this comment.
Do we need to add a config file for this?
| ]; | ||
|
|
||
| const config = { | ||
| devtool: isProduction ? |
There was a problem hiding this comment.
Is the devServer config to be added in a future PR?
There was a problem hiding this comment.
Maybe I read the docs incorrectly, but it seemed like the defaults worked?
There was a problem hiding this comment.
Right, the defaults do work, but do we want to be explicit about which port to use? Also, similar to HMR, do we want to enable "Fast Refresh" with https://github.com/pmmmwh/react-refresh-webpack-plugin ?
There was a problem hiding this comment.
- I think the port defaults to
'auto'which seems like it would be more flexible than specifying it explicitly (and the CLI prints out what it chose). - We could add
openif you like (I prefer not automatically opening the browser, but that's just me). - What does that plugin do compared to the default dev server?
There was a problem hiding this comment.
I think the port defaults to 'auto' which seems like it would be more flexible than specifying it explicitly (and the CLI prints out what it chose).
Gotcha. Let's leave it as is then.
We could add open if you like (I prefer not automatically opening the browser, but that's just me).
I don't have a preference so I'm fine leaving it as false.
What does that plugin do compared to the default dev server?
It's for preserving states of any modified React components. e.g. Say we are modifying a button in a modal window, with conventional HMR the modal window will be closed when the page auto reloads. With Fast Refresh, the modal window will remain open without us clicking again in the browser. Another example is with Fast Refresh, any existing text input is preserved in a text field when the page auto reloads.
| }, | ||
| output: { | ||
| path: path.resolve(dirname, "dist"), | ||
| filename: "[name].[contenthash].bundle.js", |
There was a problem hiding this comment.
The contenthash has been causing issues with HMR / Fast Refresh in my experience and I recommend removing such in a dev environment setting.
| filename: "[name].[contenthash].bundle.js", | |
| filename: isProduction? | |
| "[name].[contenthash].bundle.js": | |
| "[name].bundle.js", |
| "main": "src/main.js", | ||
| "scripts": { | ||
| "dev": "NODE_ENV=development nodemon src/main.js", | ||
| "prod": "NODE_ENV=production node src/main.js", |
Co-authored-by: Junhao Liao <junhao@junhao.ca>
Co-authored-by: Junhao Liao <junhao@junhao.ca>
Co-authored-by: Junhao Liao <junhao@junhao.ca>
Co-authored-by: Junhao Liao <junhao@junhao.ca>
junhaoliao
left a comment
There was a problem hiding this comment.
Looks good to me. The PR title is fine for the squashed commit message.
Co-authored-by: Junhao Liao <junhao@junhao.ca>
Co-authored-by: Junhao Liao <junhao@junhao.ca>
Description
Following #442, this PR adds a boilerplate client written using React.
For consistency, the server's
package.jsonwas also changed to:log-viewer-webui-servernpm run watchValidation performed
npm lint:checkpasses.npm run watchstarts a local HTTP server that keeps track of source changes.npm run buildbuilds a bundle indistthat can be served withnpx http-server dist