Skip to content

Commit 7cb38d2

Browse files
authored
Merge pull request #45 from YASHMAHAKAL/restore-npm-run-dev
fix: standardize webpack 5 dev server, fix MUI exports, and migrate to ESLint v10 flat config to restore npm run dev
2 parents c9c60db + 6ef80ea commit 7cb38d2

File tree

6 files changed

+116
-143
lines changed

6 files changed

+116
-143
lines changed

.eslintrc

Lines changed: 0 additions & 66 deletions
This file was deleted.

eslint.config.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
const pluginReact = require('eslint-plugin-react');
2+
const pluginJsxA11y = require('eslint-plugin-jsx-a11y');
3+
const pluginReactHooks = require('eslint-plugin-react-hooks');
4+
const globals = require('globals');
5+
6+
module.exports = [
7+
{
8+
ignores: ['dist/**', 'build/**', 'coverage/**', 'docs/**'],
9+
},
10+
{
11+
files: ['src/**/*.{js,jsx}', 'examples/**/*.{js,jsx}', 'test/**/*.{js,jsx}', '*.js'],
12+
languageOptions: {
13+
ecmaVersion: 2020,
14+
sourceType: 'module',
15+
parserOptions: {
16+
ecmaFeatures: {
17+
jsx: true,
18+
},
19+
},
20+
globals: {
21+
...globals.browser,
22+
...globals.node,
23+
...globals.mocha,
24+
...globals.es2020,
25+
},
26+
},
27+
settings: {
28+
react: {
29+
version: 'latest',
30+
},
31+
},
32+
plugins: {
33+
react: pluginReact,
34+
'jsx-a11y': pluginJsxA11y,
35+
'react-hooks': pluginReactHooks,
36+
},
37+
rules: {
38+
...pluginJsxA11y.configs.recommended.rules,
39+
'no-console': 'off',
40+
semi: 2,
41+
'no-undef': 2,
42+
'no-undef-init': 2,
43+
'no-tabs': 2,
44+
'react/self-closing-comp': 2,
45+
'react/no-typos': 2,
46+
'react/jsx-no-duplicate-props': 'warn',
47+
'react-hooks/rules-of-hooks': 'error',
48+
'react-hooks/exhaustive-deps': 'warn',
49+
'jsx-a11y/no-autofocus': [
50+
2,
51+
{
52+
ignoreNonDOM: true,
53+
},
54+
],
55+
},
56+
},
57+
];

examples/Router/index.js

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { createRoot } from 'react-dom/client';
3-
import { HashRouter as Router, Route, Switch, withRouter } from 'react-router-dom';
3+
import { HashRouter as Router, Route, Routes, useNavigate, useLocation } from 'react-router-dom';
44
import { withStyles } from 'tss-react/mui';
55
import ExamplesGrid from './ExamplesGrid';
66
import examples from '../examples';
@@ -17,58 +17,52 @@ const styles = {
1717
},
1818
};
1919

20-
class Examples extends React.Component {
21-
returnHome = () => {
22-
this.props.history.push('/');
23-
};
20+
function Examples({ classes }) {
21+
const navigate = useNavigate();
22+
const location = useLocation();
2423

25-
render() {
26-
const { classes } = this.props;
24+
const defaultTheme = createTheme();
25+
const returnHomeStyle = { padding: '0px', margin: '20px 0 20px 0' };
2726

28-
var returnHomeStyle = { padding: '0px', margin: '20px 0 20px 0' };
29-
30-
const defaultTheme = createTheme();
31-
32-
return (
33-
<ThemeProvider theme={defaultTheme}>
34-
<main className={classes.root}>
35-
<div className={classes.contentWrapper}>
36-
<Switch>
37-
<Route path="/" exact render={() => <ExamplesGrid examples={examples} />} />
38-
{Object.keys(examples).map((label, index) => (
39-
<Route
40-
key={index}
41-
path={`/${label.replace(/\s+/g, '-').toLowerCase()}`}
42-
exact
43-
component={examples[label]}
44-
/>
45-
))}
46-
</Switch>
47-
<div>
48-
{this.props.location.pathname !== '/' && (
49-
<div style={returnHomeStyle}>
50-
<Button color="primary" onClick={this.returnHome}>
51-
Back to Example Index
52-
</Button>
53-
</div>
54-
)}
55-
</div>
27+
return (
28+
<ThemeProvider theme={defaultTheme}>
29+
<main className={classes.root}>
30+
<div className={classes.contentWrapper}>
31+
<Routes>
32+
<Route path="/" element={<ExamplesGrid examples={examples} />} />
33+
{Object.keys(examples).map((label, index) => (
34+
<Route
35+
key={index}
36+
path={`/${label.replace(/\s+/g, '-').toLowerCase()}`}
37+
element={React.createElement(examples[label])}
38+
/>
39+
))}
40+
</Routes>
41+
<div>
42+
{location.pathname !== '/' && (
43+
<div style={returnHomeStyle}>
44+
<Button color="primary" onClick={() => navigate('/')}>
45+
Back to Example Index
46+
</Button>
47+
</div>
48+
)}
5649
</div>
57-
</main>
58-
</ThemeProvider>
59-
);
60-
}
50+
</div>
51+
</main>
52+
</ThemeProvider>
53+
);
6154
}
6255

63-
const StyledExamples = withRouter(withStyles(Examples, styles));
56+
const StyledExamples = withStyles(Examples, styles);
6457

6558
function App() {
6659
return (
67-
<Router hashType="noslash">
60+
<Router>
6861
<StyledExamples />
6962
</Router>
7063
);
7164
}
65+
7266
const container = document.getElementById('app-root');
7367
const root = createRoot(container);
7468
root.render(<App />);

package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"dist"
88
],
99
"scripts": {
10-
"dev": "cross-env NODE_ENV=development webpack-dev-server -d --progress --colors",
10+
"dev": "cross-env NODE_ENV=development webpack-dev-server --progress --color",
1111
"test": "cross-env NODE_ENV=test mocha --require ./test/babel-register.js --extensions js,jsx test/**/*.test.js",
1212
"docs:dev": "next docs",
1313
"docs:build": "cross-env NODE_ENV=production next build docs",
@@ -38,12 +38,13 @@
3838
"homepage": "https://github.com/layer5io/mui-datatables#readme",
3939
"devDependencies": {
4040
"@babel/core": "^7.29.0",
41+
"@babel/eslint-parser": "^7.27.1",
4142
"@babel/plugin-external-helpers": "^7.27.1",
43+
"@babel/plugin-transform-async-to-generator": "^7.28.6",
4244
"@babel/plugin-transform-class-properties": "^7.25.9",
4345
"@babel/plugin-transform-nullish-coalescing-operator": "^7.26.6",
4446
"@babel/plugin-transform-object-rest-spread": "^7.25.9",
4547
"@babel/plugin-transform-optional-chaining": "^7.25.9",
46-
"@babel/plugin-transform-async-to-generator": "^7.28.6",
4748
"@babel/plugin-transform-runtime": "^7.29.0",
4849
"@babel/preset-env": "^7.29.2",
4950
"@babel/preset-react": "^7.28.5",
@@ -58,7 +59,6 @@
5859
"@rollup/plugin-commonjs": "^29.0.2",
5960
"@rollup/plugin-node-resolve": "^16.0.3",
6061
"@rollup/plugin-replace": "^6.0.3",
61-
"@babel/eslint-parser": "^7.27.1",
6262
"babel-loader": "^10.1.1",
6363
"babel-plugin-istanbul": "^7.0.1",
6464
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
@@ -68,12 +68,13 @@
6868
"css-loader": "^7.1.4",
6969
"enzyme": "^3.11.0",
7070
"eslint": "^10.1.0",
71-
"eslint-webpack-plugin": "^5.0.3",
7271
"eslint-plugin-filenames": "^1.3.2",
7372
"eslint-plugin-import": "^2.32.0",
7473
"eslint-plugin-jsx-a11y": "^6.10.2",
7574
"eslint-plugin-react": "^7.37.5",
7675
"eslint-plugin-react-hooks": "^7.0.1",
76+
"eslint-webpack-plugin": "^5.0.3",
77+
"globals": "^17.4.0",
7778
"html-webpack-plugin": "^5.6.6",
7879
"ignore-styles": "^5.0.1",
7980
"jsdom": "^29.0.1",

webpack.config.js

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
11
const path = require('path');
22
const webpack = require('webpack');
3-
const HtmlWebpackPlugin = require('html-webpack-plugin');
4-
const ESLintPlugin = require('eslint-webpack-plugin');
53

64
module.exports = {
5+
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
76
entry: {
87
app: ['core-js/stable', 'regenerator-runtime/runtime', './examples/Router/index.js'],
98
},
10-
stats: 'verbose',
9+
stats: 'errors-warnings',
1110
context: __dirname,
1211
output: {
1312
filename: 'bundle.js',
1413
},
1514
devtool: 'source-map',
16-
resolve: {
17-
mainFields: ['browser', 'module', 'main'],
18-
},
1915
devServer: {
20-
disableHostCheck: true,
16+
static: { directory: path.resolve(__dirname) },
17+
allowedHosts: 'all',
2118
host: 'localhost',
2219
hot: true,
23-
inline: true,
2420
port: process.env.PORT || 5050,
25-
stats: 'errors-warnings',
2621
},
2722
module: {
2823
rules: [
@@ -31,37 +26,15 @@ module.exports = {
3126
exclude: /node_modules/,
3227
use: ['babel-loader'],
3328
},
34-
{
35-
test: /\.(js|jsx)$/,
36-
include: /node_modules\/(@mui|@emotion)\//,
37-
use: {
38-
loader: 'babel-loader',
39-
options: {
40-
presets: [
41-
['@babel/preset-env', { modules: 'commonjs' }],
42-
'@babel/preset-react',
43-
],
44-
plugins: [
45-
'@babel/plugin-transform-optional-chaining',
46-
'@babel/plugin-transform-nullish-coalescing-operator',
47-
],
48-
},
49-
},
50-
},
5129
{
5230
test: /\.css$/i,
5331
use: ['style-loader', 'css-loader'],
5432
},
5533
],
5634
},
5735
plugins: [
58-
new ESLintPlugin({ extensions: ['js', 'jsx'] }),
59-
new webpack.HotModuleReplacementPlugin(),
60-
new webpack.NamedModulesPlugin(),
6136
new webpack.DefinePlugin({
62-
'process.env': {
63-
NODE_ENV: JSON.stringify('development'),
64-
},
37+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
6538
}),
6639
],
6740
};

0 commit comments

Comments
 (0)