Skip to content

Instantly share code, notes, and snippets.

@thedanbob
Created January 13, 2020 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thedanbob/36e3d85802e6344d41c6ca9971a7e474 to your computer and use it in GitHub Desktop.
Save thedanbob/36e3d85802e6344d41c6ca9971a7e474 to your computer and use it in GitHub Desktop.
Load cocoon JS with webpacker
// app/javascripts/packs/application.js
import 'cocoon'
// config/webpack/environment.js
const { environment } = require('@rails/webpacker')
environment.plugins.prepend('GemAssetsPlugin', require('./plugins/gem-assets'))
module.exports = environment
// config/webpack/plugins/gem-assets.js
const { exec } = require('child_process')
module.exports = {
apply(compiler) {
compiler.hooks.beforeRun.tap('GemAssetsPlugin', (compilation) => {
exec('mkdir -p vendor/assets/javascripts')
exec('cp $(env -u DEBUG bundle show cocoon)/app/assets/javascripts/cocoon.js vendor/assets/javascripts')
return true
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment