From 27e53ed20b9a19d8284220a05b4274cb6b75f470 Mon Sep 17 00:00:00 2001 From: Alejandro Lembke Barrientos Date: Tue, 16 Aug 2022 20:48:02 +0000 Subject: [PATCH] PR-536602: making more changing to fix css. --- src/server/server.tsx | 8 +++++--- src/server/utilsServer.ts | 15 ++++++++++----- webpack.config.ts | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/server/server.tsx b/src/server/server.tsx index b372ab8..ff4fb88 100644 --- a/src/server/server.tsx +++ b/src/server/server.tsx @@ -30,9 +30,9 @@ const routesUrls = routes.map( route => route.path); const app = express(); +// @ts-ignore:next-line +const compiler = webpack(webpackConfig); if(env === 'development'){ - // @ts-ignore:next-line - const compiler = webpack(webpackConfig); const serverConfig = { serverSideRender: true, publicPath: webpackConfig.output?.publicPath, @@ -72,6 +72,8 @@ const setResponse = (html, preloadedState, manifest) => { const mainBuild = manifest ? manifest['frontend.js'] : 'assets/app.js'; const vendorBuild = manifest ? manifest['vendors.js'] : 'assets/vendor.js'; const manifestJson = manifest ? `` : ''; + const memoryFs = compiler.outputFileSystem + const haveVendor = haveVendorsCss(manifest, memoryFs) return(` @@ -84,7 +86,7 @@ const setResponse = (html, preloadedState, manifest) => { ${manifestJson} - ${haveVendorsCss() ? `` : ''} + ${haveVendor ? `` : ''} App diff --git a/src/server/utilsServer.ts b/src/server/utilsServer.ts index ccc695e..64e45d8 100644 --- a/src/server/utilsServer.ts +++ b/src/server/utilsServer.ts @@ -1,20 +1,25 @@ import fs from 'fs'; +import config from '../../config'; + +const { env } = config export const getHashManifest = () => { try { const baseUrl = __dirname.replace(/\/server(.*)/,''); - const fullURL = `${baseUrl}/assets/manifest-hash.json` ; - return JSON.parse(fs.readFileSync(fullURL).toString()); + const fullURL = `${baseUrl}/assets/manifest-hash.json`; + const readFileData = JSON.parse(fs.readFileSync(fullURL).toString()); + return readFileData }catch(err){ console.error(err); } }; -export const haveVendorsCss = () => { +export const haveVendorsCss = (manifest, memoryFs) => { try { const baseUrl = __dirname.replace(/\/server(.*)/,''); - const fullURL = `${baseUrl}/assets/vendors.css` ; - fs.readFileSync(fullURL).toString(); + const fullURL = `${baseUrl}${manifest ? manifest['vendors.css'] : '/build/assets/vendors.css'}`; + env === 'production' && fs.readFileSync(fullURL).toString(); + env === 'development' && memoryFs.readFileSync(fullURL).toString(); return true }catch(err){ // console.error(err); diff --git a/webpack.config.ts b/webpack.config.ts index c8ba900..aed3e6e 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -198,7 +198,7 @@ const serverConfig = { filename: '[path][base].gz', }), new MiniCssExtractPlugin({ - filename: 'assets/[name]/app-[fullhash].css', + filename: 'assets/[name]-[fullhash].css', }), new WebpackManifestPlugin({ fileName: 'assets/manifest-hash.json',