-
Notifications
You must be signed in to change notification settings - Fork 3
How To Use Webpacker
Instructions to use Webpacker for Blacklight 7 to compile javascript assets, as of 7/19/18, these instructions have some inaccuracies and are in general incomplete, but a good starting point for figuring all this out. (https://www.npmjs.com/package/blacklight-frontend):
-
If Node.js and NPM are not already installed on your machine, this might help http://blog.teamtreehouse.com/install-node-js-npm-mac (basically, use
homebrew
) -
Check your Node.js version and upgrade if required since Webpacker requires Node.js >= 6.0.0. Currently my local versions are as below:
$ npm -v 6.1.0
$ node -v v10.6.0
-
$ brew install yarn
-
To Install Webpacker just ran the below since it is already added in the
Gemfile
. If it wasn't in theGemfile
, you could rungem add webpacker
$ bundle $ bundle exec rails webpacker:install
TODO: we should be clear about what
bundle exec rails webpacker:install
does. -
To install all the dependencies listed within
package.json
in the localnode_modules
folder, just run$ yarn install
You could just use yarn
too, which does the same thing as yarn install
. Yarn will take the config set in webpacker.yml
. We have set check_yarn_integrity: true
which generates integrity digests on our yarn.lock
file, which will jive well with production deployment which wants to generate these digests too (see desc "Compile JavaScript packs using webpack for production with digests"
in compile.rake
in the webpacker gem.
3 terminal tabs:
$ rails s
-
$ bin/webpack-dev-server
(does live code reloading, nice!) $ bundle exec rails solr:up
or just run
$ bundle exec foreman start -f Procfile.dev
All of the scss, images and javascript can be put into the /app/javascript
directory. Here's what my directory looks like right now:
.
├── packs
│ └── application.js
├── psulib_blacklight
│ ├── fonts
│ ├── images
│ │ ├── index.js
│ │ └── logo.png
│ ├── index.js
│ └── styles
│ ├── app.scss
│ └── blacklight_marc.scss
└── src
└── js
The idea is that you set all of the assets needed for your application in one sub-directory with that sub-directory having the name of your app (i.e., psulib_blacklight
). Inside this app sub-directory you need fonts
, images
and styles
sub-directories. All of this is compiled into the index.js
file. And this is called by the application.js
file (under packs
) that simply imports psulib_blaclight
. In order for blacklight to use webpacker for scss all of the core scss and the blacklight-marc scss have to be added as front-end dependencies in package.json
. Then these scss files are called in by app.scss
. Because the blacklight_marc scss had some problems, I actually just duplicated the scss file from that repo and moved it into the styles folder with some adjustments. I left blacklight-marc in the package.json
file just for clarity in terms of understanding that we rely on it.
For images, you'll see that there is an index.js
file in the images
directory. That file is a manifest of all the images you want webpacker to bring in.
The last piece is making sure that <%= stylesheet_pack_tag 'application' %>
and <%= javascript_pack_tag 'application' %>
are being called from an erb file somewhere (base.html.erb
in our case). Notice that we say application
. Then notice that the file inside the packs
directory is called application.js
. One could have as many packs as is wanted and include them where ever you want.
And this last point leads into more that could be done. Webpacker is really geared for introducing event-based javascript and web components. So, while we don't ever have to take advantage of that, it'd be easy to add this kind of functionality.
TODO: more documentation on environment.rb
and the rest of the config inside config/webpacker
.
Your Yarn packages are out of date!
Please run `yarn install` to update.
This is what solved the above issue for me:
$ brew uninstall --force yarn
$ rm -rf ~/.yarn
$ brew install yarn
$ brew link --overwrite yarn
$ yarn install
$ rails webpacker:install
Note from @cdm32: I just ran yarn install
in that case and it worked for me. But, yeah, if there's an underlying issue with brew
, that could be a problem.
Bootsnap is a gem used to speed up local development. We have experienced a problem where clearing the cache that bootsnap builds is necessary. Here's how:
- go to the project home, then cd into tmp/cache
- delete bootsnap-load-path-cache and bootsnap-compile-cache
- Home
- Testing Documentation for Product Owner
- Components, Features, and Functions
- Library Faceting and Locations Management
- Advanced Search
- Browse Items By Library of Congress Call Number
- Browse by Subject, Author, and Title
- Availability Display
- Summary Holdings Display
- Holdings and Availability for Bound-Withs
- Holds and ILL
- Requesting Items with Aeon
- Course Reserves
- Google Books and HathiTrust Integration
- Bento Integration
- Indexing and Display
- Sources of Catalog Data
- Display Fields
- Title Fields
- Author and Creator Fields
- Thesis Department
- ISSNs and ISBNs
- URL Fields
- Publication and Edition Fields
- Material Characteristics Fields
- Language Fields
- Subject Fields
- Genre Fields
- Note Fields
- Serials
- Bound-Withs
- Formats
- Media Types
- Access Facet
- Open Access Facet
- Call Numbers
- OCLC Number
- LCCN
- Report Numbers
- Endowment Codes and Names
- Adding Linked to Request Scanning
- Summary Holdings Indexing
- My Account
- Tests
- Development Setup and Notes
- Deployment Notes