Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BRS 7 - Full SSR Hard Source and Loadable support #77

Closed
wants to merge 27 commits into from

Conversation

ajones513
Copy link

@ajones513 ajones513 changed the title Custom Full SSR, Hard Source plugin Apr 14, 2020
Copy link
Member

@olliecurtis olliecurtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good but have a few clarifying questions that need answering just for future maintaining of this especially in the .ssr.js file as this is just a copy of the webpack.config.js file but modified for SSR.

@@ -55,6 +57,10 @@ const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
// Some apps do not need the benefits of saving a web request, so not inlining the chunk
// makes for a smoother build process.
const shouldInlineRuntimeChunk = process.env.INLINE_RUNTIME_CHUNK !== 'false';
// We might not want to use the hard source plugin on environments that won't persist the cache for later
const useHardSourceWebpackPlugin =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than an env variable this might be better as a config value instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it's experimental (mainly because mzgoddard/hard-source-webpack-plugin#419 + waiting for Webpack 5), I've found value in flipping it on/off at will - so was thinking the environment variables maybe gave more flexibility.

If there's cleaner way without needing to make a code change in the consuming project that would still be good.

@@ -54,6 +56,10 @@ const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
// Some apps do not need the benefits of saving a web request, so not inlining the chunk
// makes for a smoother build process.
// const shouldInlineRuntimeChunk = process.env.INLINE_RUNTIME_CHUNK !== 'false';
// We might not want to use the hard source plugin on environments that won't persist the cache for later
const useHardSourceWebpackPlugin =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@@ -82,7 +88,7 @@ module.exports = function(webpackEnv) {
: isEnvDevelopment && '/';
// Some apps do not use client-side routing with pushState.
// For these, "homepage" can be set to "." to enable relative asset paths.
const shouldUseRelativeAssetPaths = publicPath === './';
// const shouldUseRelativeAssetPaths = publicPath === './';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you confirm why this has been removed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was only used by MiniCssExtractPlugin

shouldUseRelativeAssetPaths ? { publicPath: '../../' } : undefined
),
},
// isEnvDevelopment && require.resolve('style-loader'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you confirm why this has been removed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In standard CRA, in development, styles are served client-side only, via the Webpack dev server. The CSS is served inside the .js assets.

I didn't want to get into changing that - so in development, SSR should just ignore styles completely.

new webpack.DefinePlugin(env.stringified),
new webpack.DefinePlugin({
...env.stringified,
'typeof window': '"undefined"',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you confirm what this is doing?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://webpack.js.org/plugins/define-plugin/#usage - defining typeof window is the closest I've seen to a 'standard' way of stripping out client/server-only code from their respective bundles.

// This is necessary to emit hot updates (currently CSS only):
isEnvDevelopment && new webpack.HotModuleReplacementPlugin(),
// isEnvDevelopment && new webpack.HotModuleReplacementPlugin(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you confirm why this has been removed?

Copy link
Author

@ajones513 ajones513 Apr 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above re: styles, and I don't think https://webpack.js.org/concepts/hot-module-replacement/ is designed for the server.

filename: 'ssr.css',
// chunkFilename: 'static/css/[name].[contenthash:8].chunk.css',
}),
// isEnvProduction &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you confirm why this has been removed? Guessing it relates to the HardSourcePlugin?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the styles again.

@olliecurtis olliecurtis changed the base branch from fork to brs-v7.0.5 July 16, 2020 14:01
@olliecurtis olliecurtis changed the title Full SSR, Hard Source plugin BRS 7 - Full SSR, Hard Source plugin Sep 23, 2020
@olliecurtis olliecurtis changed the title BRS 7 - Full SSR, Hard Source plugin BRS 7 - Full SSR Hard Source and Loadable support Jun 4, 2021
@olliecurtis
Copy link
Member

olliecurtis commented Jan 17, 2022

Closing this PR as v7 is no longer supported version at Skyscanner - these changes have been ported to newer versions and also improved in #95

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants