Skip to content

Commit

Permalink
refactor: Disable hashing ssr-build's css (#1733)
Browse files Browse the repository at this point in the history
* refactor: Disable hashing ssr-build's css

* docs: Adding changeset

* test: Fix unrelated change from altered template
  • Loading branch information
rschristian committed Jan 7, 2023
1 parent 1702ead commit 482b140
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/popular-zebras-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'preact-cli': patch
---

Disables hash in CSS file names for the SSR build
6 changes: 4 additions & 2 deletions packages/cli/src/lib/webpack/run-webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ async function devBuild(env) {
}

async function prodBuild(env) {
env = { ...env, isServer: false, dev: !env.production, ssr: false };
let config = await clientConfig(env);
await transformConfig(env, config);

if (env.prerender) {
let ssrConfig = serverConfig(env);
await transformConfig(env, ssrConfig, true);
const serverEnv = Object.assign({}, env, { isServer: true, ssr: true });
let ssrConfig = serverConfig(serverEnv);
await transformConfig(serverEnv, ssrConfig);
let serverCompiler = webpack(ssrConfig);
await runCompiler(serverCompiler);
}
Expand Down
13 changes: 2 additions & 11 deletions packages/cli/src/lib/webpack/transform-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function parseConfig(config) {
return transformers;
}

module.exports = async function (env, webpackConfig, isServer = false) {
module.exports = async function (env, webpackConfig) {
const { configFile, isDefault } =
env.config !== 'preact.config.js'
? { configFile: env.config, isDefault: false }
Expand Down Expand Up @@ -122,16 +122,7 @@ module.exports = async function (env, webpackConfig, isServer = false) {
const helpers = new WebpackConfigHelpers(env.cwd);
for (let [transformer, options] of transformers) {
try {
await transformer(
webpackConfig,
Object.assign({}, env, {
isServer,
dev: !env.production,
ssr: isServer,
}),
helpers,
options
);
await transformer(webpackConfig, env, helpers, options);
} catch (err) {
throw new Error((`Error at ${cliConfig}: \n` + err && err.stack) || err);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/lib/webpack/webpack-base-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ module.exports = function createBaseConfig(env) {
// Fix for https://github.com/webpack-contrib/mini-css-extract-plugin/issues/151
new RemoveEmptyScriptsPlugin(),
new MiniCssExtractPlugin({
filename: isProd ? '[name].[contenthash:5].css' : '[name].css',
filename:
isProd && !env.isServer ? '[name].[contenthash:5].css' : '[name].css',
chunkFilename: isProd
? '[name].chunk.[contenthash:5].css'
: '[name].chunk.css',
Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/lib/webpack/webpack-server-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ function serverConfig(env) {
publicPath: '/',
filename: 'ssr-bundle.js',
path: resolve(env.dest, 'ssr-build'),
chunkFilename: '[name].chunk.[chunkhash:5].js',
libraryTarget: 'commonjs2',
},
externals: {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/tests/images/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ exports.default = {
'assets/preact-logo-inverse.svg': 649,
'assets/favicon.ico': 15086,

'ssr-build/ssr-bundle.dba70.css': 1281,
'ssr-build/ssr-bundle.dba70.css.map': 2069,
'ssr-build/ssr-bundle.css': 1281,
'ssr-build/ssr-bundle.css.map': 2069,
'ssr-build/ssr-bundle.js': 26049,
'ssr-build/ssr-bundle.js.map': 63276,
'ssr-build/asset-manifest.json': 76,
Expand Down

0 comments on commit 482b140

Please sign in to comment.