Skip to content

Commit

Permalink
Fixes #37775 - include hashes in production builds of assets
Browse files Browse the repository at this point in the history
(cherry picked from commit cd1ea00)
  • Loading branch information
evgeni authored and ekohl committed Sep 2, 2024
1 parent 65b8a67 commit b85db59
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/helpers/reactjs_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def read_webpack_manifest

def get_webpack_chunk(name, extension)
data = read_webpack_manifest
data['assetsByChunkName'][name].find { |value| value.end_with?(".#{extension}") }
data['assetsByChunkName'][name]&.find { |value| value.end_with?(".#{extension}") }
end

def get_webpack_foreman_vendor_js
Expand Down
8 changes: 4 additions & 4 deletions app/views/layouts/base.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
</script>
<%= javascript_include_tag "locale/#{FastGettext.locale}/app" %>
<%= locale_js_tags %>
<%= yield(:head) %>
</head>

<body class='<%= body_css_classes %>'>
<%= get_webpack_foreman_vendor_js %>
<%= javascript_include_tag('/webpack/vendor.js') %>
<%= javascript_include_tag('/webpack/bundle.js') %>
<%= javascript_include_tag('/webpack/reactExports.js') %>
<%= javascript_include_tag("/webpack/#{get_webpack_chunk('vendor', 'js')}") %>
<%= javascript_include_tag("/webpack/#{get_webpack_chunk('bundle', 'js')}") %>
<%= javascript_include_tag("/webpack/#{get_webpack_chunk('reactExports', 'js')}") %>
<%= javascript_include_tag 'application' %>
<%= webpacked_plugins_with_global_js %>
Expand Down
10 changes: 10 additions & 0 deletions config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ const coreConfig = function() {
'webpack/assets/javascripts/bundle.js'
);
config.context = path.resolve(__dirname, '..');
if (config.mode == 'production') {
var chunkFilename = '[name]-[chunkhash].js'
} else {
var chunkFilename = '[name].js'
}

config.entry = {
bundle: { import: bundleEntry, dependOn: ['vendor', 'reactExports'] },
vendor: vendorEntry,
Expand All @@ -169,6 +175,7 @@ const coreConfig = function() {
name: ['TheForeman', '[name]'],
type: 'var',
},
filename: chunkFilename,
};
var plugins = config.plugins;

Expand Down Expand Up @@ -236,6 +243,7 @@ const pluginConfig = function(plugin) {

if (config.mode == 'production') {
var outputPath = path.join(pluginRoot, 'public', 'webpack', pluginName);
var chunkFilename = '[name]-[chunkhash].js'
} else {
var outputPath = path.join(
__dirname,
Expand All @@ -244,10 +252,12 @@ const pluginConfig = function(plugin) {
'webpack',
pluginName
);
var chunkFilename = '[name].js'
}
config.output = {
path: outputPath,
publicPath: '/webpack/' + pluginName + '/',
filename: chunkFilename,
uniqueName: pluginName,
};
var configModules = config.resolve.modules || [];
Expand Down

0 comments on commit b85db59

Please sign in to comment.