mirror of
https://github.com/aleleba/create-react-ssr.git
synced 2025-01-09 21:46:56 -06:00
PR-753737: Se agrega ESLint a webpack.
This commit is contained in:
parent
e87a638e7d
commit
d6f2d2d5dd
7
src/.eslintignore
Normal file
7
src/.eslintignore
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#Build
|
||||||
|
build
|
||||||
|
#Webpack
|
||||||
|
webpack.config.js
|
||||||
|
webpack.config.dev.js
|
||||||
|
#Server
|
||||||
|
/server/index.js
|
51
src/.eslintrc.js
Normal file
51
src/.eslintrc.js
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
module.exports = {
|
||||||
|
'env': {
|
||||||
|
'browser': true,
|
||||||
|
'node': true,
|
||||||
|
'es2021': true
|
||||||
|
},
|
||||||
|
'extends': [
|
||||||
|
'eslint:recommended',
|
||||||
|
'plugin:react/recommended',
|
||||||
|
'plugin:@typescript-eslint/recommended'
|
||||||
|
],
|
||||||
|
'parser': '@typescript-eslint/parser',
|
||||||
|
'parserOptions': {
|
||||||
|
'ecmaFeatures': {
|
||||||
|
'jsx': true
|
||||||
|
},
|
||||||
|
'ecmaVersion': 'latest',
|
||||||
|
'sourceType': 'module'
|
||||||
|
},
|
||||||
|
'plugins': [
|
||||||
|
'react',
|
||||||
|
'@typescript-eslint'
|
||||||
|
],
|
||||||
|
'rules': {
|
||||||
|
'indent': [
|
||||||
|
'error',
|
||||||
|
'tab'
|
||||||
|
],
|
||||||
|
'linebreak-style': [
|
||||||
|
'error',
|
||||||
|
'unix'
|
||||||
|
],
|
||||||
|
'quotes': [
|
||||||
|
'error',
|
||||||
|
'single'
|
||||||
|
],
|
||||||
|
'semi': [
|
||||||
|
'error',
|
||||||
|
'always'
|
||||||
|
],
|
||||||
|
'eol-last': [
|
||||||
|
'error',
|
||||||
|
'always'
|
||||||
|
]
|
||||||
|
},
|
||||||
|
'settings': {
|
||||||
|
'react': {
|
||||||
|
'version': 'detect',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
@ -1,11 +1,11 @@
|
|||||||
const PRName = function () {
|
const PRName = function () {
|
||||||
let ID = "";
|
let ID = '';
|
||||||
// let characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
// let characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||||
let characters = "0123456789";
|
const characters = '0123456789';
|
||||||
for ( var i = 0; i < 6; i++ ) {
|
for ( let i = 0; i < 6; i++ ) {
|
||||||
ID += characters.charAt(Math.floor(Math.random() * 10));
|
ID += characters.charAt(Math.floor(Math.random() * 10));
|
||||||
}
|
}
|
||||||
return 'PR-'+ID;
|
return 'PR-'+ID;
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(PRName())
|
console.log(PRName());
|
||||||
|
@ -3,6 +3,6 @@ const config = {
|
|||||||
port: process.env.PORT ? process.env.PORT : 80,
|
port: process.env.PORT ? process.env.PORT : 80,
|
||||||
// portDev: process.env.PORT_DEV ? process.env.PORT_DEV : 3000,
|
// portDev: process.env.PORT_DEV ? process.env.PORT_DEV : 3000,
|
||||||
// portReloadDev: process.env.PORT_RELOAD_DEV,
|
// portReloadDev: process.env.PORT_RELOAD_DEV,
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports = { config: config };
|
module.exports = { config: config };
|
@ -1,6 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PrincipalRoutes from './PrincipalRoutes';
|
import PrincipalRoutes from './PrincipalRoutes';
|
||||||
|
|
||||||
const App = () => <PrincipalRoutes />
|
const App = () => <PrincipalRoutes />;
|
||||||
|
|
||||||
export default App;
|
export default App;
|
@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
const InitialComponent = () => <h1>Hello React!</h1>
|
const InitialComponent = () => <h1>Hello React!</h1>;
|
||||||
|
|
||||||
export default InitialComponent;
|
export default InitialComponent;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
const OtherComponent = () => <h1>Other Component!</h1>
|
const OtherComponent = () => <h1>Other Component!</h1>;
|
||||||
|
|
||||||
export default OtherComponent;
|
export default OtherComponent;
|
||||||
|
@ -5,7 +5,7 @@ import routes from '../../routes';
|
|||||||
|
|
||||||
const PrincipalRoutes = () => {
|
const PrincipalRoutes = () => {
|
||||||
let element = useRoutes(routes);
|
let element = useRoutes(routes);
|
||||||
return element
|
return element;
|
||||||
}
|
};
|
||||||
|
|
||||||
export default PrincipalRoutes;
|
export default PrincipalRoutes;
|
@ -21,13 +21,13 @@ import './styles/global.sass';
|
|||||||
}
|
}
|
||||||
} */
|
} */
|
||||||
|
|
||||||
const { env } = config
|
const { env } = config;
|
||||||
|
|
||||||
const composeEnhancers = composeWithDevToolsWeb({
|
const composeEnhancers = composeWithDevToolsWeb({
|
||||||
// Specify here name, actionsBlacklist, actionsCreators and other options
|
// Specify here name, actionsBlacklist, actionsCreators and other options
|
||||||
});
|
});
|
||||||
|
|
||||||
const preloadedState = window.__PRELOADED_STATE__
|
const preloadedState = window.__PRELOADED_STATE__;
|
||||||
|
|
||||||
const store = env === 'development' ? createStore(
|
const store = env === 'development' ? createStore(
|
||||||
reducer,
|
reducer,
|
||||||
@ -36,14 +36,15 @@ const store = env === 'development' ? createStore(
|
|||||||
) : createStore(
|
) : createStore(
|
||||||
reducer,
|
reducer,
|
||||||
preloadedState,
|
preloadedState,
|
||||||
)
|
);
|
||||||
|
|
||||||
delete window.__PRELOADED_STATE__
|
delete window.__PRELOADED_STATE__;
|
||||||
|
|
||||||
const container = document.getElementById('app');
|
const container = document.getElementById('app');
|
||||||
const history = createBrowserHistory()
|
const history = createBrowserHistory();
|
||||||
|
|
||||||
const root = hydrateRoot(container,
|
// add "const root" to be able to rerender.
|
||||||
|
hydrateRoot(container,
|
||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
<Router history={history}>
|
<Router history={history}>
|
||||||
<App />
|
<App />
|
||||||
|
@ -4,6 +4,6 @@ import testReducer from './testReducer';
|
|||||||
const rootReducer = combineReducers({
|
const rootReducer = combineReducers({
|
||||||
// Here comes the reducers
|
// Here comes the reducers
|
||||||
testReducer
|
testReducer
|
||||||
})
|
});
|
||||||
|
|
||||||
export default rootReducer
|
export default rootReducer;
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
let initialState = {}
|
let initialState = {};
|
||||||
|
|
||||||
export default initialState
|
export default initialState;
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
const initialState = {
|
const initialState = {
|
||||||
hello: 'world'
|
hello: 'world'
|
||||||
}
|
};
|
||||||
|
|
||||||
let testReducer = (state = initialState, action) => {
|
let testReducer = (state = initialState, action) => {
|
||||||
switch (action.type){
|
switch (action.type){
|
||||||
case 'CHANGE_HELLO': {
|
case 'CHANGE_HELLO': {
|
||||||
let newHello = action.payload.hello
|
let newHello = action.payload.hello;
|
||||||
return {
|
return {
|
||||||
hello: newHello
|
hello: newHello
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return state
|
return state;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export default testReducer
|
export default testReducer;
|
||||||
|
2799
src/package-lock.json
generated
2799
src/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -6,6 +6,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "nodemon server/index",
|
"start": "nodemon server/index",
|
||||||
"build": "webpack-cli --config webpack.config.js",
|
"build": "webpack-cli --config webpack.config.js",
|
||||||
|
"lint": "eslint ./ --ext .js --ext .ts --ext .jsx --ext .tsx",
|
||||||
|
"lint:fix": "eslint ./ --ext .js --ext .ts --ext .jsx --ext .tsx --fix",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
@ -44,11 +46,16 @@
|
|||||||
"@babel/preset-env": "^7.16.11",
|
"@babel/preset-env": "^7.16.11",
|
||||||
"@babel/preset-react": "^7.16.7",
|
"@babel/preset-react": "^7.16.7",
|
||||||
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.5",
|
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.5",
|
||||||
|
"@typescript-eslint/eslint-plugin": "^5.20.0",
|
||||||
|
"@typescript-eslint/parser": "^5.20.0",
|
||||||
"babel-loader": "^8.2.4",
|
"babel-loader": "^8.2.4",
|
||||||
"clean-webpack-plugin": "^4.0.0",
|
"clean-webpack-plugin": "^4.0.0",
|
||||||
"compression-webpack-plugin": "^9.2.0",
|
"compression-webpack-plugin": "^9.2.0",
|
||||||
"css-loader": "^6.7.1",
|
"css-loader": "^6.7.1",
|
||||||
"css-minimizer-webpack-plugin": "^3.4.1",
|
"css-minimizer-webpack-plugin": "^3.4.1",
|
||||||
|
"eslint": "^8.13.0",
|
||||||
|
"eslint-plugin-react": "^7.29.4",
|
||||||
|
"eslint-webpack-plugin": "^3.1.1",
|
||||||
"mini-css-extract-plugin": "^2.6.0",
|
"mini-css-extract-plugin": "^2.6.0",
|
||||||
"nodemon": "^2.0.15",
|
"nodemon": "^2.0.15",
|
||||||
"react-refresh": "^0.12.0",
|
"react-refresh": "^0.12.0",
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
import React from "react";
|
import React from 'react';
|
||||||
import InitialComponent from "../frontend/components/InitialComponent";
|
import InitialComponent from '../frontend/components/InitialComponent';
|
||||||
import OtherComponent from "../frontend/components/OtherComponent";
|
import OtherComponent from '../frontend/components/OtherComponent';
|
||||||
|
|
||||||
const OTHER_COMPONENT = {
|
const OTHER_COMPONENT = {
|
||||||
path: 'other-component',
|
path: 'other-component',
|
||||||
element: <OtherComponent />
|
element: <OtherComponent />
|
||||||
}
|
};
|
||||||
|
|
||||||
const INITIAL_COMPONENT = {
|
const INITIAL_COMPONENT = {
|
||||||
path: '/',
|
path: '/',
|
||||||
element: <InitialComponent />,
|
element: <InitialComponent />,
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
export default [ INITIAL_COMPONENT, OTHER_COMPONENT ]
|
export default [ INITIAL_COMPONENT, OTHER_COMPONENT ];
|
||||||
|
@ -2,10 +2,10 @@ import fs from 'fs';
|
|||||||
|
|
||||||
const getHashManifest = () => {
|
const getHashManifest = () => {
|
||||||
try {
|
try {
|
||||||
return JSON.parse(fs.readFileSync(`${__dirname}/../build/assets/manifest-hash.json`))
|
return JSON.parse(fs.readFileSync(`${__dirname}/../build/assets/manifest-hash.json`));
|
||||||
}catch(err){
|
}catch(err){
|
||||||
console.error(err)
|
console.error(err);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export default getHashManifest
|
export default getHashManifest;
|
||||||
|
@ -3,9 +3,9 @@ require('dotenv').config();
|
|||||||
require('ignore-styles');
|
require('ignore-styles');
|
||||||
|
|
||||||
require('@babel/register')({
|
require('@babel/register')({
|
||||||
"presets": [
|
'presets': [
|
||||||
"@babel/preset-env",
|
'@babel/preset-env',
|
||||||
"@babel/preset-react"
|
'@babel/preset-react'
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ import webpackHotMiddleware from 'webpack-hot-middleware';
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { renderToString } from 'react-dom/server';
|
import { renderToString } from 'react-dom/server';
|
||||||
//Router
|
//Router
|
||||||
import { StaticRouter } from "react-router-dom/server";
|
import { StaticRouter } from 'react-router-dom/server';
|
||||||
//Redux
|
//Redux
|
||||||
import { createStore } from 'redux'; //, applyMiddleware
|
import { createStore } from 'redux'; //, applyMiddleware
|
||||||
import { Provider } from 'react-redux';
|
import { Provider } from 'react-redux';
|
||||||
@ -24,7 +24,7 @@ import getHashManifest from './getHashManifest';
|
|||||||
//App
|
//App
|
||||||
import App from '../frontend/components/App';
|
import App from '../frontend/components/App';
|
||||||
|
|
||||||
const { env, port } = config
|
const { env, port } = config;
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ if(env === 'development'){
|
|||||||
app
|
app
|
||||||
.use(webpackDevMiddleware(compiler, serverConfig))
|
.use(webpackDevMiddleware(compiler, serverConfig))
|
||||||
.use(webpackHotMiddleware(compiler, {
|
.use(webpackHotMiddleware(compiler, {
|
||||||
path: "/reload_wss",
|
path: '/reload_wss',
|
||||||
heartbeat: 1000,
|
heartbeat: 1000,
|
||||||
}));
|
}));
|
||||||
}else{
|
}else{
|
||||||
@ -54,7 +54,7 @@ if(env === 'development'){
|
|||||||
contentSecurityPolicy: {
|
contentSecurityPolicy: {
|
||||||
directives: {
|
directives: {
|
||||||
...helmet.contentSecurityPolicy.getDefaultDirectives(),
|
...helmet.contentSecurityPolicy.getDefaultDirectives(),
|
||||||
"script-src": ["'self'", "'unsafe-inline'"],//"example.com"
|
'script-src': ['\'self\'', '\'unsafe-inline\''],//"example.com"
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
@ -85,11 +85,11 @@ const setResponse = (html, preloadedState, manifest) => {
|
|||||||
<script src="${vendorBuild}" type="text/javascript"></script>
|
<script src="${vendorBuild}" type="text/javascript"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
`)
|
`);
|
||||||
}
|
};
|
||||||
|
|
||||||
const renderApp = (req, res) => {
|
const renderApp = (req, res) => {
|
||||||
const store = createStore(reducer, initialState)
|
const store = createStore(reducer, initialState);
|
||||||
const preloadedState = store.getState();
|
const preloadedState = store.getState();
|
||||||
const html = renderToString(
|
const html = renderToString(
|
||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
@ -97,13 +97,13 @@ const renderApp = (req, res) => {
|
|||||||
<App />
|
<App />
|
||||||
</StaticRouter>
|
</StaticRouter>
|
||||||
</Provider>
|
</Provider>
|
||||||
)
|
);
|
||||||
res.send(setResponse(html, preloadedState, req.hashManifest));
|
res.send(setResponse(html, preloadedState, req.hashManifest));
|
||||||
};
|
};
|
||||||
|
|
||||||
app.get('*', renderApp)
|
app.get('*', renderApp);
|
||||||
|
|
||||||
app.listen(port, (err) => {
|
app.listen(port, (err) => {
|
||||||
if(err) console.error(err)
|
if(err) console.error(err);
|
||||||
else console.log(`Server running on port ${port}`);
|
else console.log(`Server running on port ${port}`);
|
||||||
});
|
});
|
@ -3,6 +3,7 @@ const dotenv = require('dotenv').config();
|
|||||||
const webpack = require('webpack');
|
const webpack = require('webpack');
|
||||||
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
||||||
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
|
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
|
||||||
|
const ESLintPlugin = require('eslint-webpack-plugin');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
entry: ['webpack-hot-middleware/client?path=/reload_wss&timeout=2000&overlay=false&reload=true', './frontend/index.js'],
|
entry: ['webpack-hot-middleware/client?path=/reload_wss&timeout=2000&overlay=false&reload=true', './frontend/index.js'],
|
||||||
@ -44,6 +45,7 @@ module.exports = {
|
|||||||
new MiniCssExtractPlugin({
|
new MiniCssExtractPlugin({
|
||||||
filename: 'assets/app.css',
|
filename: 'assets/app.css',
|
||||||
}),
|
}),
|
||||||
|
new ESLintPlugin(),
|
||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
'process.env': JSON.stringify(dotenv.parsed),
|
'process.env': JSON.stringify(dotenv.parsed),
|
||||||
}),
|
}),
|
||||||
@ -67,4 +69,4 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
|
@ -7,6 +7,7 @@ const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
|
|||||||
const TerserPlugin = require('terser-webpack-plugin');
|
const TerserPlugin = require('terser-webpack-plugin');
|
||||||
const { WebpackManifestPlugin } = require('webpack-manifest-plugin');
|
const { WebpackManifestPlugin } = require('webpack-manifest-plugin');
|
||||||
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
||||||
|
const ESLintPlugin = require('eslint-webpack-plugin');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
entry: './frontend/index.js',
|
entry: './frontend/index.js',
|
||||||
@ -54,6 +55,7 @@ module.exports = {
|
|||||||
fileName: 'assets/manifest-hash.json',
|
fileName: 'assets/manifest-hash.json',
|
||||||
}),
|
}),
|
||||||
new CleanWebpackPlugin(),
|
new CleanWebpackPlugin(),
|
||||||
|
new ESLintPlugin(),
|
||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
'process.env': JSON.stringify(dotenv.parsed),
|
'process.env': JSON.stringify(dotenv.parsed),
|
||||||
}),
|
}),
|
||||||
@ -82,4 +84,4 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user