Created
September 24, 2017 05:22
-
-
Save n0nick/b18a7978b8f27f56fe1bda33ff11ebd7 to your computer and use it in GitHub Desktop.
Adding gem paths to Webpacker config
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/test.js | |
const environment = require('./environment'); | |
const webpackConfigWithGems = require('./utils/webpack_config_with_gems'); | |
module.exports = webpackConfigWithGems(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/utils/webpack_config_with_gems.js | |
const { execSync } = require('child_process'); | |
function getGemPath(gemName, path) { | |
const gemPath = execSync(`bundle show ${gemName}`).toString().trim(); | |
return `${gemPath}/${path}/assets/javascripts`; | |
} | |
module.exports = function(environment) { | |
const config = environment.toWebpackConfig(); | |
config.resolve.modules.push( | |
getGemPath('js-routes', 'app'), | |
getGemPath('client_side_validations', 'vendor'), | |
getGemPath('client_side_validations-simple_form', 'vendor'), | |
getGemPath('i18n-js', 'app') | |
); | |
return config; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment