Skip to content

Commit

Permalink
feat(assets) create widget.js files (#1453)
Browse files Browse the repository at this point in the history
  • Loading branch information
hgw77 authored Nov 5, 2024
1 parent afc304f commit a873b1b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
10 changes: 2 additions & 8 deletions config/esbuild/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ const entryPoints = require("./entrypoints")
const esbuild = require("esbuild")
const args = process.argv.slice(2)
const watch = args.indexOf("--watch") >= 0
const production =
args.indexOf("--production") >= 0 || process.env.RAILS_ENV === "production"
const production = args.indexOf("--production") >= 0 || process.env.RAILS_ENV === "production"
const log = console.log.bind(console)

const config = {
Expand All @@ -40,8 +39,6 @@ const config = {
),
bundle: true,
platform: "browser",
// format: "esm",
// splitting: true,
outdir: "app/assets/builds",
plugins: [
envFilePlugin,
Expand Down Expand Up @@ -176,10 +173,7 @@ function compile(options = {}) {
return esbuild
.build(config)
.then(() => {
log(
green,
"◻️ Compile completed successfully with no errors! Don't worry Be Happy 🙂"
)
log(green, "◻️ Compile completed successfully with no errors! Don't worry Be Happy 🙂")
})
.catch((error) => {
log(red, "Compile completed with error 😐")
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/assets.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Be sure to restart your server when you modify this file.

# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = "1.0"
Rails.application.config.assets.version = '1.0'

# Add additional assets to the asset load path.
# Rails.application.config.assets.paths << Emoji.images_path
Expand Down
17 changes: 17 additions & 0 deletions config/initializers/sprockets_processor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# The main purpose of this code is to create a copy of '_widget.js' files without the digest (hash) in the file name.
# This allows to access these assets with a consistent name without having the hash in the file name.
module NonDigestAssets
def self.call(input)
filename = input[:filename]
# check if the file is a _widget.js file
# copy the file to the public/assets folder
if filename.end_with?('_widget.js')
# without the digest in the file name
path = File.join(Rails.public_path, 'assets', File.basename(filename))
FileUtils.cp(filename, path)
end
nil
end
end

Sprockets.register_postprocessor 'application/javascript', NonDigestAssets

0 comments on commit a873b1b

Please sign in to comment.