Skip to content

Instantly share code, notes, and snippets.

@n0nick
Created September 24, 2017 05:22
Show Gist options
  • Save n0nick/b18a7978b8f27f56fe1bda33ff11ebd7 to your computer and use it in GitHub Desktop.
Save n0nick/b18a7978b8f27f56fe1bda33ff11ebd7 to your computer and use it in GitHub Desktop.
Adding gem paths to Webpacker config
// config/webpack/test.js
const environment = require('./environment');
const webpackConfigWithGems = require('./utils/webpack_config_with_gems');
module.exports = webpackConfigWithGems(environment);
// 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