Skip to content

Commit 29da589

Browse files
authored
refactor: Disable hashing ssr-build's css (#1733)
* refactor: Disable hashing ssr-build's css * docs: Adding changeset * test: Fix unrelated change from altered template
1 parent e12393c commit 29da589

File tree

7 files changed

+30
-33
lines changed

7 files changed

+30
-33
lines changed

.changeset/popular-zebras-yell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'preact-cli': patch
3+
---
4+
5+
Disables hash in CSS file names for the SSR build

packages/cli/lib/lib/webpack/run-webpack.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,14 @@ async function devBuild(env) {
5252
}
5353

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

5859
if (env.prerender) {
59-
let ssrConfig = serverConfig(env);
60-
await transformConfig(env, ssrConfig, true);
60+
const serverEnv = Object.assign({}, env, { isServer: true, ssr: true });
61+
let ssrConfig = serverConfig(serverEnv);
62+
await transformConfig(serverEnv, ssrConfig);
6163
let serverCompiler = webpack(ssrConfig);
6264
await runCompiler(serverCompiler);
6365
}

packages/cli/lib/lib/webpack/transform-config.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function parseConfig(config) {
9090
return transformers;
9191
}
9292

93-
module.exports = async function (env, webpackConfig, isServer = false) {
93+
module.exports = async function (env, webpackConfig) {
9494
const { configFile, isDefault } =
9595
env.config !== 'preact.config.js'
9696
? { configFile: env.config, isDefault: false }
@@ -122,16 +122,7 @@ module.exports = async function (env, webpackConfig, isServer = false) {
122122
const helpers = new WebpackConfigHelpers(env.cwd);
123123
for (let [transformer, options] of transformers) {
124124
try {
125-
await transformer(
126-
webpackConfig,
127-
Object.assign({}, env, {
128-
isServer,
129-
dev: !env.production,
130-
ssr: isServer,
131-
}),
132-
helpers,
133-
options
134-
);
125+
await transformer(webpackConfig, env, helpers, options);
135126
} catch (err) {
136127
throw new Error((`Error at ${cliConfig}: \n` + err && err.stack) || err);
137128
}

packages/cli/lib/lib/webpack/webpack-base-config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@ module.exports = function createBaseConfig(env) {
290290
// Fix for https://github.com/webpack-contrib/mini-css-extract-plugin/issues/151
291291
new RemoveEmptyScriptsPlugin(),
292292
new MiniCssExtractPlugin({
293-
filename: isProd ? '[name].[contenthash:5].css' : '[name].css',
293+
filename:
294+
isProd && !env.isServer ? '[name].[contenthash:5].css' : '[name].css',
294295
chunkFilename: isProd
295296
? '[name].chunk.[contenthash:5].css'
296297
: '[name].chunk.css',

packages/cli/lib/lib/webpack/webpack-server-config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ function serverConfig(env) {
1414
publicPath: '/',
1515
filename: 'ssr-bundle.js',
1616
path: resolve(env.dest, 'ssr-build'),
17-
chunkFilename: '[name].chunk.[chunkhash:5].js',
1817
libraryTarget: 'commonjs2',
1918
},
2019
externals: {

packages/cli/tests/images/build.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ exports.default = {
77
'assets/icons/mstile-150x150.png': 9050,
88
'assets/favicon.ico': 15086,
99

10-
'ssr-build/ssr-bundle.c9123.css': 1281,
11-
'ssr-build/ssr-bundle.c9123.css.map': 2070,
10+
'ssr-build/ssr-bundle.css': 1281,
11+
'ssr-build/ssr-bundle.css.map': 2070,
1212
'ssr-build/ssr-bundle.js': 9801,
1313
'ssr-build/ssr-bundle.js.map': 30625,
14-
'ssr-build/asset-manifest.json': 82,
14+
'ssr-build/asset-manifest.json': 76,
1515

16-
'bundle.3c823.js': 21323,
17-
'bundle.3c823.js.map': 85534,
18-
'bundle.3c823.legacy.js': 22514,
19-
'bundle.3c823.legacy.js.map': 106422,
20-
'bundle.a2557.css': 945,
21-
'bundle.a2557.css.map': 1758,
16+
'bundle.620ee.js': 21323,
17+
'bundle.620ee.js.map': 85534,
18+
'bundle.620ee.legacy.js': 22514,
19+
'bundle.620ee.legacy.js.map': 106422,
20+
'bundle.354c3.css': 945,
21+
'bundle.354c3.css.map': 1758,
2222

2323
'dom-polyfills.c88f4.legacy.js': 5252,
2424
'dom-polyfills.c88f4.legacy.js.map': 18836,
@@ -31,17 +31,17 @@ exports.default = {
3131
'push-manifest.json': 450,
3232
'asset-manifest.json': 943,
3333

34-
'route-home.chunk.a00bd.js': 339,
35-
'route-home.chunk.a00bd.js.map': 1811,
36-
'route-home.chunk.a00bd.legacy.js': 394,
37-
'route-home.chunk.a00bd.legacy.js.map': 2102,
34+
'route-home.chunk.4ad71.js': 339,
35+
'route-home.chunk.4ad71.js.map': 1811,
36+
'route-home.chunk.4ad71.legacy.js': 394,
37+
'route-home.chunk.4ad71.legacy.js.map': 2102,
3838
'route-home.chunk.6eaee.css': 112,
3939
'route-home.chunk.6eaee.css.map': 224,
4040

41-
'route-profile.chunk.05dd0.js': 2545,
42-
'route-profile.chunk.05dd0.js.map': 10268,
43-
'route-profile.chunk.05dd0.legacy.js': 2698,
44-
'route-profile.chunk.05dd0.legacy.js.map': 12894,
41+
'route-profile.chunk.6a61d.js': 2545,
42+
'route-profile.chunk.6a61d.js.map': 10268,
43+
'route-profile.chunk.6a61d.legacy.js': 2698,
44+
'route-profile.chunk.6a61d.legacy.js.map': 12894,
4545
'route-profile.chunk.0af3e.css': 118,
4646
'route-profile.chunk.0af3e.css.map': 231,
4747
};

packages/create-cli/tests/images/create.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ exports.default = [
1111
'src/assets/icons/favicon-16x16.png',
1212
'src/assets/icons/favicon-32x32.png',
1313
'src/assets/icons/mstile-150x150.png',
14-
'src/components/app.js',
1514
'src/components/header/index.js',
1615
'src/components/header/style.module.css',
1716
'src/index.js',

0 commit comments

Comments
 (0)