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 Dec 22, 2022
1 parent 8fdb28a commit c7703a8
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 18 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 @@ -52,12 +52,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
6 changes: 3 additions & 3 deletions packages/cli/tests/images/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ exports.default = {
'assets/icons/mstile-150x150.png': 9050,
'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': 82,
'ssr-build/asset-manifest.json': 76,

'bundle.79d07.js': 21560,
'bundle.79d07.js.map': 85822,
Expand Down

0 comments on commit c7703a8

Please sign in to comment.