soapbox/webpack/configuration.js

37 wiersze
1.0 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-04-16 23:50:41 +00:00
const settings = safeLoad(readFileSync(configPath), 'utf8')[env.NODE_ENV];
2020-03-27 20:59:38 +00:00
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 = {
path: join(__dirname, '..', 'static', settings.public_output_path),
2020-03-27 20:59:38 +00:00
publicPath: formatPublicPath(env.CDN_HOST, settings.public_output_path),
};
module.exports = {
settings,
env: {
CDN_HOST: env.CDN_HOST,
NODE_ENV: env.NODE_ENV,
},
output,
};