Skip to content

Instantly share code, notes, and snippets.

@bbonamin
Forked from thedanbob/application.js
Created March 26, 2020 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbonamin/51b2484773f0dbdeea97b5a19460f2a5 to your computer and use it in GitHub Desktop.
Save bbonamin/51b2484773f0dbdeea97b5a19460f2a5 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