Created
January 13, 2020 16:05
-
-
Save thedanbob/36e3d85802e6344d41c6ca9971a7e474 to your computer and use it in GitHub Desktop.
Load cocoon JS with webpacker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// app/javascripts/packs/application.js | |
import 'cocoon' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// config/webpack/environment.js | |
const { environment } = require('@rails/webpacker') | |
environment.plugins.prepend('GemAssetsPlugin', require('./plugins/gem-assets')) | |
module.exports = environment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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