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 authored Aug 13, 2022
1 parent e12393c commit 29da589
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 33 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/lib/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/lib/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/lib/lib/webpack/webpack-base-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,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/lib/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
34 changes: 17 additions & 17 deletions packages/cli/tests/images/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ exports.default = {
'assets/icons/mstile-150x150.png': 9050,
'assets/favicon.ico': 15086,

'ssr-build/ssr-bundle.c9123.css': 1281,
'ssr-build/ssr-bundle.c9123.css.map': 2070,
'ssr-build/ssr-bundle.css': 1281,
'ssr-build/ssr-bundle.css.map': 2070,
'ssr-build/ssr-bundle.js': 9801,
'ssr-build/ssr-bundle.js.map': 30625,
'ssr-build/asset-manifest.json': 82,
'ssr-build/asset-manifest.json': 76,

'bundle.3c823.js': 21323,
'bundle.3c823.js.map': 85534,
'bundle.3c823.legacy.js': 22514,
'bundle.3c823.legacy.js.map': 106422,
'bundle.a2557.css': 945,
'bundle.a2557.css.map': 1758,
'bundle.620ee.js': 21323,
'bundle.620ee.js.map': 85534,
'bundle.620ee.legacy.js': 22514,
'bundle.620ee.legacy.js.map': 106422,
'bundle.354c3.css': 945,
'bundle.354c3.css.map': 1758,

'dom-polyfills.c88f4.legacy.js': 5252,
'dom-polyfills.c88f4.legacy.js.map': 18836,
Expand All @@ -31,17 +31,17 @@ exports.default = {
'push-manifest.json': 450,
'asset-manifest.json': 943,

'route-home.chunk.a00bd.js': 339,
'route-home.chunk.a00bd.js.map': 1811,
'route-home.chunk.a00bd.legacy.js': 394,
'route-home.chunk.a00bd.legacy.js.map': 2102,
'route-home.chunk.4ad71.js': 339,
'route-home.chunk.4ad71.js.map': 1811,
'route-home.chunk.4ad71.legacy.js': 394,
'route-home.chunk.4ad71.legacy.js.map': 2102,
'route-home.chunk.6eaee.css': 112,
'route-home.chunk.6eaee.css.map': 224,

'route-profile.chunk.05dd0.js': 2545,
'route-profile.chunk.05dd0.js.map': 10268,
'route-profile.chunk.05dd0.legacy.js': 2698,
'route-profile.chunk.05dd0.legacy.js.map': 12894,
'route-profile.chunk.6a61d.js': 2545,
'route-profile.chunk.6a61d.js.map': 10268,
'route-profile.chunk.6a61d.legacy.js': 2698,
'route-profile.chunk.6a61d.legacy.js.map': 12894,
'route-profile.chunk.0af3e.css': 118,
'route-profile.chunk.0af3e.css.map': 231,
};
Expand Down
1 change: 0 additions & 1 deletion packages/create-cli/tests/images/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ exports.default = [
'src/assets/icons/favicon-16x16.png',
'src/assets/icons/favicon-32x32.png',
'src/assets/icons/mstile-150x150.png',
'src/components/app.js',
'src/components/header/index.js',
'src/components/header/style.module.css',
'src/index.js',
Expand Down

0 comments on commit 29da589

Please sign in to comment.