soapbox/webpack/configuration.js

41 wiersze
1.2 KiB
JavaScript
Czysty Zwykły widok Historia

2020-03-27 20:59:38 +00:00
// Common configuration for webpacker loaded from config/webpacker.yml
2020-03-28 00:35:00 +00:00
const { join } = require('path');
2020-03-27 20:59:38 +00:00
const { env } = require('process');
const { safeLoad } = require('js-yaml');
const { readFileSync } = require('fs');
2020-03-28 00:35:00 +00:00
const configPath = join(__dirname, 'config', 'webpacker.yml');
2020-03-27 20:59:38 +00:00
const settings = safeLoad(readFileSync(configPath), 'utf8')[env.RAILS_ENV || env.NODE_ENV];
2020-03-28 00:35:00 +00:00
const themePath = join(__dirname, 'config', 'themes.yml');
2020-03-27 20:59:38 +00:00
const themes = safeLoad(readFileSync(themePath), 'utf8');
function removeOuterSlashes(string) {
return string.replace(/^\/*/, '').replace(/\/*$/, '');
}
function formatPublicPath(host = '', path = '') {
let formattedHost = removeOuterSlashes(host);
if (formattedHost && !/^http/i.test(formattedHost)) {
formattedHost = `//${formattedHost}`;
}
const formattedPath = removeOuterSlashes(path);
return `${formattedHost}/${formattedPath}/`;
}
const output = {
2020-03-28 00:35:00 +00:00
path: join(__dirname, '..', 'public', settings.public_output_path),
2020-03-27 20:59:38 +00:00
publicPath: formatPublicPath(env.CDN_HOST, settings.public_output_path),
};
module.exports = {
settings,
themes,
env: {
CDN_HOST: env.CDN_HOST,
NODE_ENV: env.NODE_ENV,
},
output,
};