Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose the original, uncompiled assets in importmaps #2995

Merged
merged 1 commit into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/assets/config/blacklight/manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//= link_tree ../../images
//= link_directory ../../stylesheets .css
//= link_tree ../../../javascript .js
4 changes: 2 additions & 2 deletions app/javascript/blacklight/bookmark_toggle.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Blacklight from './core'
import CheckboxSubmit from './checkbox_submit'
import Blacklight from 'blacklight/core'
import CheckboxSubmit from 'blacklight/checkbox_submit'

const BookmarkToggle = (() => {
// change form submit toggle to checkbox
Expand Down
10 changes: 5 additions & 5 deletions app/javascript/blacklight/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import BookmarkToggle from './bookmark_toggle'
import ButtonFocus from './button_focus'
import Modal from './modal'
import SearchContext from './search_context'
import Core from './core'
import BookmarkToggle from 'blacklight/bookmark_toggle'
import ButtonFocus from 'blacklight/button_focus'
import Modal from 'blacklight/modal'
import SearchContext from 'blacklight/search_context'
import Core from 'blacklight/core'

export default {
BookmarkToggle,
Expand Down
4 changes: 2 additions & 2 deletions app/javascript/blacklight/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
can be a turbo-stream that defines some HTML fragementsand where on the page to put them:
https://turbo.hotwired.dev/handbook/streams
*/
import Blacklight from './core'
import ModalForm from './modalForm'
import Blacklight from 'blacklight/core'
import ModalForm from 'blacklight/modalForm'

const Modal = (() => {
// We keep all our data in Blacklight.modal object.
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/blacklight/search_context.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Blacklight from './core'
import Blacklight from 'blacklight/core'

const SearchContext = (() => {
Blacklight.doSearchContextBehavior = function() {
Expand Down
2 changes: 1 addition & 1 deletion config/importmap.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# frozen_string_literal: true

pin_all_from File.expand_path("../app/javascript/blacklight", __dir__)
pin_all_from File.expand_path("../app/javascript/blacklight", __dir__), under: "blacklight"
13 changes: 6 additions & 7 deletions lib/blacklight/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ class Engine < Rails::Engine
end
end

initializer "blacklight.assets.precompile" do
# rubocop:disable Lint/ConstantDefinitionInBlock
PRECOMPILE_ASSETS = %w(favicon.ico blacklight/blacklight.js blacklight/blacklight.js.map blacklight/blacklight.esm.js blacklight/blacklight.esm.js.map).freeze
# rubocop:enable Lint/ConstantDefinitionInBlock
PRECOMPILE_ASSETS = %w(favicon.ico blacklight/blacklight.js blacklight/blacklight.js.map blacklight/blacklight.esm.js blacklight/blacklight.esm.js.map).freeze

initializer "blacklight.assets.precompile" do |app|
# When Rails has been generated in API mode, it does not have sprockets available
if Rails.application.config.respond_to?(:assets)
Rails.application.config.assets.precompile += PRECOMPILE_ASSETS
end
next unless app.config.respond_to?(:assets)

app.config.assets.paths << Engine.root.join("app/javascript")
app.config.assets.precompile += Blacklight::Engine::PRECOMPILE_ASSETS
end

initializer "blacklight.importmap", before: "importmap" do |app|
Expand Down
9 changes: 7 additions & 2 deletions lib/generators/blacklight/assets/importmap_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ def import_javascript_assets
<<~CONTENT
pin "@popperjs/core", to: "https://ga.jspm.io/npm:@popperjs/core@2.11.6/dist/umd/popper.min.js"
pin "bootstrap", to: "https://ga.jspm.io/npm:bootstrap@#{(defined?(Bootstrap) && Bootstrap::VERSION) || '5.2.2'}/dist/js/bootstrap.js"
pin "blacklight", to: "blacklight/blacklight.js"
CONTENT
end

append_to_file 'app/assets/config/manifest.js' do
<<~CONTENT
//= link blacklight/manifest.js
CONTENT
end
end
Expand All @@ -25,7 +30,7 @@ def append_blacklight_javascript
append_to_file 'app/javascript/application.js' do
<<~CONTENT
import bootstrap from "bootstrap"
import "blacklight"
import Blacklight from "blacklight"
CONTENT
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/generators/blacklight/assets/sprockets_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def appease_sprockets4
return if Rails.version > '7' || Sprockets::VERSION < '4'

append_to_file 'app/assets/config/manifest.js', "\n//= link application.js"
append_to_file 'app/assets/config/manifest.js', "\n//= link blacklight/manifest.js"
empty_directory 'app/assets/images'
end

Expand All @@ -42,6 +43,7 @@ def assets
// Required by Blacklight
//= require popper
//= require bootstrap
//= require blacklight/blacklight
CONTENT
end
end
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"url": "git+https://github.com/projectblacklight/blacklight.git"
},
"files": [
"app/assets"
"app/assets",
"app/javascript"
],
"author": "",
"license": "Apache-2.0",
Expand All @@ -21,7 +22,8 @@
},
"homepage": "https://github.com/projectblacklight/blacklight#readme",
"devDependencies": {
"rollup": "^2.60.0"
"rollup": "^2.60.0",
"rollup-plugin-includepaths": "^0.2.4"
},
"browserslist": [
"defaults",
Expand Down
12 changes: 11 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

import includePaths from 'rollup-plugin-includepaths';

const path = require('path')

const BUNDLE = process.env.BUNDLE === 'true'
Expand All @@ -9,6 +11,13 @@ const fileDest = `blacklight${ESM ? '.esm' : ''}`
const external = []
const globals = {}

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

const rollupConfig = {
input: path.resolve(__dirname, `app/javascript/blacklight/index.js`),
output: {
Expand All @@ -17,7 +26,8 @@ const rollupConfig = {
globals,
generatedCode: 'es2015'
},
external
external,
plugins: [includePaths(includePathOptions)]
}

if (!ESM) {
Expand Down