闭社主体 forked from https://github.com/tootsuite/mastodon
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.

35 lines
1.0 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.NODE_ENV];
  9. function removeOuterSlashes(string) {
  10. return string.replace(/^\/*/, '').replace(/\/*$/, '');
  11. }
  12. function formatPublicPath(host = '', path = '') {
  13. let formattedHost = removeOuterSlashes(host);
  14. if (formattedHost && !/^http/i.test(formattedHost)) {
  15. formattedHost = `//${formattedHost}`;
  16. }
  17. const formattedPath = removeOuterSlashes(path);
  18. return `${formattedHost}/${formattedPath}/`;
  19. }
  20. const output = {
  21. path: resolve('public', settings.public_output_path),
  22. publicPath: formatPublicPath(env.ASSET_HOST, settings.public_output_path),
  23. };
  24. module.exports = {
  25. settings,
  26. env,
  27. loadersDir,
  28. output,
  29. };