diff --git a/package-lock.json b/package-lock.json index c18dd07..b992cf3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@aleleba/create-react-ssr", - "version": "3.0.51", + "version": "3.1.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@aleleba/create-react-ssr", - "version": "3.0.51", + "version": "3.1.2", "license": "MIT", "dependencies": { "@babel/register": "^7.18.9", @@ -49,7 +49,7 @@ "@testing-library/react": "^13.3.0", "@testing-library/user-event": "^14.4.3", "@types/jest": "^28.1.6", - "@types/node": "^18.6.5", + "@types/node": "^18.7.0", "@types/react": "^18.0.17", "@types/react-dom": "^18.0.6", "@types/webpack": "^5.28.0", @@ -3516,9 +3516,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "18.6.5", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.6.5.tgz", - "integrity": "sha512-Xjt5ZGUa5WusGZJ4WJPbOT8QOqp6nDynVFRKcUt32bOgvXEoc6o085WNkYTMO7ifAj2isEfQQ2cseE+wT6jsRw==" + "version": "18.7.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.0.tgz", + "integrity": "sha512-MbHwEQaMKgcSQE3vFHUvxiN0+k3VpwCbnYCUigQWoKZzdIk2u7ecoCk5Vzb4lwBbKhLd2rCOUUDT35TaONs7Jw==" }, "node_modules/@types/parse5": { "version": "6.0.3", @@ -18081,9 +18081,9 @@ "dev": true }, "@types/node": { - "version": "18.6.5", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.6.5.tgz", - "integrity": "sha512-Xjt5ZGUa5WusGZJ4WJPbOT8QOqp6nDynVFRKcUt32bOgvXEoc6o085WNkYTMO7ifAj2isEfQQ2cseE+wT6jsRw==" + "version": "18.7.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.0.tgz", + "integrity": "sha512-MbHwEQaMKgcSQE3vFHUvxiN0+k3VpwCbnYCUigQWoKZzdIk2u7ecoCk5Vzb4lwBbKhLd2rCOUUDT35TaONs7Jw==" }, "@types/parse5": { "version": "6.0.3", diff --git a/package.json b/package.json index fa02338..b290e59 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@aleleba/create-react-ssr", - "version": "3.1.0", + "version": "3.1.1", "description": "Starter Kit of server side render of react", "bin": "./bin/cli.js", "main": "src/server/index", @@ -68,7 +68,7 @@ "@testing-library/react": "^13.3.0", "@testing-library/user-event": "^14.4.3", "@types/jest": "^28.1.6", - "@types/node": "^18.6.5", + "@types/node": "^18.7.0", "@types/react": "^18.0.17", "@types/react-dom": "^18.0.6", "@types/webpack": "^5.28.0", diff --git a/src/frontend/components/OtherComponent.tsx b/src/frontend/components/OtherComponent.tsx index 97f8576..7b539b9 100644 --- a/src/frontend/components/OtherComponent.tsx +++ b/src/frontend/components/OtherComponent.tsx @@ -8,7 +8,7 @@ const OtherComponent = () => (
logo

- Edit src/frontend/OtherComponent.jsx and save to reload. + Edit src/frontend/OtherComponent.jsx and save to reload.

Initial Component
diff --git a/src/server/getHashManifest.ts b/src/server/getHashManifest.ts deleted file mode 100644 index 6c92ac3..0000000 --- a/src/server/getHashManifest.ts +++ /dev/null @@ -1,13 +0,0 @@ -import fs from 'fs'; - -const getHashManifest = () => { - try { - const baseUrl = __dirname.replace(/\/server(.*)/,''); - const fullURL = `${baseUrl}/assets/manifest-hash.json` ; - return JSON.parse(fs.readFileSync(fullURL).toString()); - }catch(err){ - console.error(err); - } -}; - -export default getHashManifest; diff --git a/src/server/server.tsx b/src/server/server.tsx index 2f02af6..b372ab8 100644 --- a/src/server/server.tsx +++ b/src/server/server.tsx @@ -20,7 +20,7 @@ import { Provider } from 'react-redux'; import setStore from '../frontend/setStore'; import initialState from '../frontend/reducers/initialState'; //Get Hashes -import getHashManifest from './getHashManifest'; +import { getHashManifest, haveVendorsCss } from './utilsServer'; //App import App from '../frontend/components/App'; @@ -67,8 +67,8 @@ if(env === 'development'){ } const setResponse = (html, preloadedState, manifest) => { - const mainStyles = manifest ? manifest['frontend.css'] : 'assets/main/app.css'; - const vendorStyles = manifest ? manifest['vendors.css'] : '/assets/vendors/app.css'; + const mainStyles = manifest ? manifest['frontend.css'] : 'assets/main.css'; + const vendorStyles = manifest ? manifest['vendors.css'] : 'assets/vendors.css'; const mainBuild = manifest ? manifest['frontend.js'] : 'assets/app.js'; const vendorBuild = manifest ? manifest['vendors.js'] : 'assets/vendor.js'; const manifestJson = manifest ? `` : ''; @@ -84,7 +84,7 @@ const setResponse = (html, preloadedState, manifest) => { ${manifestJson} - + ${haveVendorsCss() ? `` : ''} App diff --git a/src/server/utilsServer.ts b/src/server/utilsServer.ts new file mode 100644 index 0000000..ccc695e --- /dev/null +++ b/src/server/utilsServer.ts @@ -0,0 +1,23 @@ +import fs from 'fs'; + +export const getHashManifest = () => { + try { + const baseUrl = __dirname.replace(/\/server(.*)/,''); + const fullURL = `${baseUrl}/assets/manifest-hash.json` ; + return JSON.parse(fs.readFileSync(fullURL).toString()); + }catch(err){ + console.error(err); + } +}; + +export const haveVendorsCss = () => { + try { + const baseUrl = __dirname.replace(/\/server(.*)/,''); + const fullURL = `${baseUrl}/assets/vendors.css` ; + fs.readFileSync(fullURL).toString(); + return true + }catch(err){ + // console.error(err); + return false + } +}; diff --git a/webpack.config.dev.ts b/webpack.config.dev.ts index 2ebfc2f..6570039 100644 --- a/webpack.config.dev.ts +++ b/webpack.config.dev.ts @@ -69,7 +69,7 @@ const config: Configuration = { new webpack.HotModuleReplacementPlugin(), new ReactRefreshWebpackPlugin(), new MiniCssExtractPlugin({ - filename: 'assets/[name]/app.css', + filename: 'assets/[name].css', }), new ESLintPlugin(), new webpack.DefinePlugin({ diff --git a/webpack.config.ts b/webpack.config.ts index c217477..c8ba900 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -76,7 +76,7 @@ const frontendConfig = { filename: '[path][base].gz', }), new MiniCssExtractPlugin({ - filename: 'assets/[name]/app-[fullhash].css', + filename: 'assets/[name]-[fullhash].css', }), new WebpackManifestPlugin({ fileName: 'assets/manifest-hash.json',