The code powering m.abunchtell.com https://m.abunchtell.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

43 lines
1.2 KiB

  1. // Common configuration for webpacker loaded from config/webpacker.yml
  2. const { join, resolve } = require('path');
  3. const { env } = require('process');
  4. const { safeLoad } = require('js-yaml');
  5. const { readFileSync } = require('fs');
  6. const configPath = resolve('config', 'webpacker.yml');
  7. const loadersDir = join(__dirname, 'loaders');
  8. const settings = safeLoad(readFileSync(configPath), 'utf8')[env.RAILS_ENV || env.NODE_ENV];
  9. const themePath = resolve('config', 'themes.yml');
  10. const themes = safeLoad(readFileSync(themePath), 'utf8');
  11. function removeOuterSlashes(string) {
  12. return string.replace(/^\/*/, '').replace(/\/*$/, '');
  13. }
  14. function formatPublicPath(host = '', path = '') {
  15. let formattedHost = removeOuterSlashes(host);
  16. if (formattedHost && !/^http/i.test(formattedHost)) {
  17. formattedHost = `//${formattedHost}`;
  18. }
  19. const formattedPath = removeOuterSlashes(path);
  20. return `${formattedHost}/${formattedPath}/`;
  21. }
  22. const output = {
  23. path: resolve('public', settings.public_output_path),
  24. publicPath: formatPublicPath(env.CDN_HOST, settings.public_output_path),
  25. };
  26. module.exports = {
  27. settings,
  28. themes,
  29. env: {
  30. CDN_HOST: env.CDN_HOST,
  31. NODE_ENV: env.NODE_ENV,
  32. },
  33. loadersDir,
  34. output,
  35. };