chore: enables webpack dev server

This commit is contained in:
Mark Mankarious 2023-03-24 23:32:36 +00:00
parent 4cb585d252
commit b86c76ed05
8 changed files with 3633 additions and 60 deletions

3564
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -10,6 +10,12 @@
}, },
"main": "./dist/index.js", "main": "./dist/index.js",
"types": "./dist/App.d.ts", "types": "./dist/App.d.ts",
"scripts": {
"start": "webpack serve --config ./webpack/dev.config.js",
"dev": "nodemon --watch ./src/ -e ts,tsx --exec npm run build",
"build": "webpack --config ./webpack/prod.config.js && tsc --declaration --emitDeclarationOnly",
"test": "jest"
},
"devDependencies": { "devDependencies": {
"@testing-library/jest-dom": "^5.16.5", "@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0", "@testing-library/react": "^13.4.0",
@ -19,7 +25,9 @@
"@types/node": "^16.18.12", "@types/node": "^16.18.12",
"@types/react": "^18.0.28", "@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11", "@types/react-dom": "^18.0.11",
"@types/webpack-env": "^1.18.0",
"concurrently": "^7.6.0", "concurrently": "^7.6.0",
"html-webpack-plugin": "^5.5.0",
"jest": "^29.5.0", "jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0", "jest-environment-jsdom": "^29.5.0",
"jsdom": "^21.1.1", "jsdom": "^21.1.1",
@ -30,7 +38,8 @@
"ts-loader": "^9.4.2", "ts-loader": "^9.4.2",
"typescript": "^4.9.5", "typescript": "^4.9.5",
"webpack": "^5.76.2", "webpack": "^5.76.2",
"webpack-cli": "^5.0.1" "webpack-cli": "^5.0.1",
"webpack-dev-server": "^4.13.1"
}, },
"dependencies": { "dependencies": {
"@emotion/react": "^11.10.6", "@emotion/react": "^11.10.6",
@ -51,11 +60,6 @@
"react": ">=17", "react": ">=17",
"react-dom": ">=17" "react-dom": ">=17"
}, },
"scripts": {
"dev": "nodemon --watch ./src/ -e ts,tsx --exec npm run build",
"build": "webpack && tsc --declaration --emitDeclarationOnly",
"test": "jest"
},
"eslintConfig": { "eslintConfig": {
"extends": [ "extends": [
"react-app", "react-app",

View file

@ -1,49 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@200;600&display=swap"
rel="stylesheet"
/>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>

16
src/index.html Normal file
View file

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@200;600&display=swap"
rel="stylesheet"
/>
<title>Development | Isoflow</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>

View file

@ -1,6 +1,7 @@
import React from "react"; import React from "react";
import ReactDOM from "react-dom/client"; import ReactDOM from "react-dom/client";
import App from "./App"; import App from "./App";
import GlobalStyles from "@mui/material/GlobalStyles";
import { mockScene } from "./mockData"; import { mockScene } from "./mockData";
const root = ReactDOM.createRoot( const root = ReactDOM.createRoot(
@ -9,6 +10,13 @@ const root = ReactDOM.createRoot(
root.render( root.render(
<React.StrictMode> <React.StrictMode>
<App initialScene={mockScene} /> <GlobalStyles
styles={{
body: {
margin: 0,
},
}}
/>
<App initialScene={mockScene} height="100vh" />
</React.StrictMode> </React.StrictMode>
); );

View file

@ -1,11 +1,9 @@
import { ModeContext, Mouse } from "./types"; import { ModeContext, Mouse } from "./types";
import { makeAutoObservable } from "mobx";
export class ModeBase { export class ModeBase {
ctx; ctx;
constructor(ctx: ModeContext) { constructor(ctx: ModeContext) {
makeAutoObservable(this);
this.ctx = ctx; this.ctx = ctx;
} }

34
webpack/dev.config.js Normal file
View file

@ -0,0 +1,34 @@
const path = require("path");
const HtmlWebPackPlugin = require("html-webpack-plugin");
module.exports = {
mode: "development",
entry: "./src/index.tsx",
output: {
filename: "main.js",
path: path.resolve(__dirname, "build"),
},
devServer: {
static: {
directory: path.join(__dirname, "build"),
},
port: 3000,
},
module: {
rules: [
{
test: /\.(ts|tsx)$/,
use: "ts-loader",
exclude: /node_modules/,
},
],
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
},
plugins: [
new HtmlWebPackPlugin({
template: path.resolve(__dirname, "../src/index.html"),
}),
],
};

View file

@ -4,7 +4,7 @@ module.exports = {
mode: "production", mode: "production",
entry: "./src/App.tsx", entry: "./src/App.tsx",
output: { output: {
path: path.resolve(__dirname, "dist"), path: path.resolve(__dirname, "../dist"),
filename: "index.js", filename: "index.js",
libraryTarget: "commonjs2", libraryTarget: "commonjs2",
}, },