Skip to content

Commit

Permalink
Use rollup so we don't need to rely on sprockets
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Dec 20, 2024
1 parent 48868d7 commit 2c85079
Show file tree
Hide file tree
Showing 17 changed files with 379 additions and 17 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.config
.yardoc
Gemfile.lock
package-lock.json
InstalledFiles
_yardoc
coverage
Expand All @@ -17,4 +18,5 @@ test/version_tmp
tmp
jetty
spec/internal
.internal_test_app
.internal_test_app
node_modules
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Run the gallery generator for Sprockets:
Or for node based bundlers add `blacklight-gallery masonry-layout@v4` as a dependencies and add this to your entrypoint:
```js
import 'blacklight-gallery/vendor/assets/javascripts/imagesloaded.pkgd.js'
import 'blacklight-gallery/app/assets/javascripts/blacklight_gallery/slideshow'
import 'blacklight-gallery/app/assets/javascripts/blacklight_gallery/masonry'
import 'blacklight-gallery/app/javascript/blacklight-gallery/slideshow'
import 'blacklight-gallery/app/javascript/blacklight-gallery/masonry'
```

## Available Views
Expand Down
156 changes: 156 additions & 0 deletions app/assets/javascripts/blacklight_gallery/blacklight-gallery.esm.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

161 changes: 161 additions & 0 deletions app/assets/javascripts/blacklight_gallery/blacklight-gallery.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions app/assets/javascripts/blacklight_gallery/default.js

This file was deleted.

2 changes: 0 additions & 2 deletions app/assets/javascripts/blacklight_gallery/osd_viewer.js

This file was deleted.

5 changes: 5 additions & 0 deletions app/javascript/blacklight-gallery/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'imagesloaded.min'
import 'masonry.min'

import 'blacklight-gallery/slideshow'
import 'blacklight-gallery/masonry'
2 changes: 1 addition & 1 deletion config/importmap.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true

pin_all_from File.expand_path('../app/assets/javascripts/blacklight_gallery', __dir__), under: 'blacklight_gallery'
pin_all_from File.expand_path('../app/javascripts/blacklight-gallery', __dir__), under: 'blacklight-gallery'
pin_all_from File.expand_path('../vendor/assets/javascripts', __dir__)
1 change: 1 addition & 0 deletions lib/blacklight/gallery/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Blacklight
module Gallery
class Engine < Rails::Engine
initializer 'blacklight_gallery.importmap', before: 'importmap' do |app|
app.config.assets.paths << Engine.root.join("app/javascript")
app.config.importmap.paths << Engine.root.join('config/importmap.rb') if app.config.respond_to?(:importmap)
end
end
Expand Down
5 changes: 2 additions & 3 deletions lib/generators/blacklight_gallery/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def add_model_mixin
end

def add_openseadragon
gem "openseadragon", ">= 0.2.0"
gem "openseadragon", "~> 1.0"
Bundler.with_clean_env { run 'bundle install' }
generate 'openseadragon:install'
end
Expand All @@ -34,10 +34,9 @@ def assets
return unless defined?(Sprockets)

append_to_file 'app/assets/config/manifest.js', "\n//= link blacklight_gallery/manifest.js\n"
copy_file "blacklight_gallery.js", "app/assets/javascripts/blacklight_gallery.js"

insert_into_file "app/assets/javascripts/application.js", after: '//= require blacklight/blacklight' do
"\n//= require blacklight_gallery"
"\n//= require blacklight-gallery/blacklight-gallery"
end
end
end
Expand Down

This file was deleted.

17 changes: 15 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@
"name": "blacklight-gallery",
"version": "4.6.4",
"description": "Gallery views for Blacklight search results",
"main": "app/assets/javascripts/blacklight_gallery/default.js",
"exports": {
".": "./app/javascript/blacklight-gallery/index.js",
"./*": "./app/javascript/blacklight-gallery/*.js"
},
"main": "app/assets/javascripts/blacklight_gallery/blacklight-gallery.esm.js",
"type": "module",
"scripts": {
"prepare": "rollup --config rollup.config.js --sourcemap && ESM=true rollup --config rollup.config.js --sourcemap"
},
"files": [
"app/assets/javascripts/blacklight_gallery/*.js",
"app/javascript/blacklight-gallery/*.js",
"vendor/assets/javascripts/*.js",
"app/assets/stylesheets/blacklight_gallery/*.scss"
],
Expand All @@ -18,9 +27,13 @@
"url": "https://github.com/projectblacklight/blacklight-gallery/issues"
},
"homepage": "https://github.com/projectblacklight/blacklight-gallery#readme",
"devDependencies": { },
"devDependencies": {
"rollup": "^4.24.0",
"rollup-plugin-includepaths": "^0.2.4"
},
"dependencies": {
"blacklight-frontend": ">=7.1.0 <9",
"openseadragon-rails": "^1.0.10",
"jquery": ">=3.0"
}
}
31 changes: 31 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import includePaths from 'rollup-plugin-includepaths';


const BUNDLE = process.env.BUNDLE === 'true'
const ESM = process.env.ESM === 'true'

const fileDest = `blacklight-gallery${ESM ? '.esm' : ''}`
const external = []
const globals = {}

let includePathOptions = {
include: {},
paths: ['app/javascript', 'vendor/assets/javascripts'],
external: [],
extensions: ['.js']
};

const rollupConfig = {
input: 'app/javascript/blacklight-gallery/index.js',
output: {
file: `app/assets/javascripts/blacklight_gallery/${fileDest}.js`,
format: ESM ? 'es' : 'umd',
globals,
generatedCode: { preset: 'es2015' },
name: ESM ? undefined : 'BlacklightGallery'
},
external,
plugins: [includePaths(includePathOptions)]
}

export default rollupConfig

0 comments on commit 2c85079

Please sign in to comment.