diff --git a/.changeset/popular-zebras-yell.md b/.changeset/popular-zebras-yell.md new file mode 100644 index 000000000..a6d2df930 --- /dev/null +++ b/.changeset/popular-zebras-yell.md @@ -0,0 +1,5 @@ +--- +'preact-cli': patch +--- + +Disables hash in CSS file names for the SSR build diff --git a/packages/cli/src/lib/webpack/run-webpack.js b/packages/cli/src/lib/webpack/run-webpack.js index 161848e3e..ad1e74caa 100644 --- a/packages/cli/src/lib/webpack/run-webpack.js +++ b/packages/cli/src/lib/webpack/run-webpack.js @@ -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); } diff --git a/packages/cli/src/lib/webpack/transform-config.js b/packages/cli/src/lib/webpack/transform-config.js index 79cee333c..9a5b1f26f 100644 --- a/packages/cli/src/lib/webpack/transform-config.js +++ b/packages/cli/src/lib/webpack/transform-config.js @@ -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 } @@ -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); } diff --git a/packages/cli/src/lib/webpack/webpack-base-config.js b/packages/cli/src/lib/webpack/webpack-base-config.js index 9b8e0ab88..443d9d7a0 100644 --- a/packages/cli/src/lib/webpack/webpack-base-config.js +++ b/packages/cli/src/lib/webpack/webpack-base-config.js @@ -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', diff --git a/packages/cli/src/lib/webpack/webpack-server-config.js b/packages/cli/src/lib/webpack/webpack-server-config.js index 6628e9732..bc3dd80b2 100644 --- a/packages/cli/src/lib/webpack/webpack-server-config.js +++ b/packages/cli/src/lib/webpack/webpack-server-config.js @@ -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: { diff --git a/packages/cli/tests/images/build.js b/packages/cli/tests/images/build.js index dd72a4e2f..9cd330d64 100644 --- a/packages/cli/tests/images/build.js +++ b/packages/cli/tests/images/build.js @@ -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,