2017-05-03 09:04:16 +09:00
|
|
|
// Common configuration for webpacker loaded from config/webpack/paths.yml
|
|
|
|
|
2017-05-21 00:31:47 +09:00
|
|
|
const { join, resolve } = require('path');
|
|
|
|
const { env } = require('process');
|
|
|
|
const { safeLoad } = require('js-yaml');
|
|
|
|
const { readFileSync } = require('fs');
|
2017-05-03 09:04:16 +09:00
|
|
|
|
2017-05-21 00:31:47 +09:00
|
|
|
const configPath = resolve('config', 'webpack');
|
|
|
|
const loadersDir = join(__dirname, 'loaders');
|
|
|
|
const paths = safeLoad(readFileSync(join(configPath, 'paths.yml'), 'utf8'))[env.NODE_ENV || 'development'];
|
|
|
|
const devServer = safeLoad(readFileSync(join(configPath, 'development.server.yml'), 'utf8'))[env.NODE_ENV || 'development'];
|
2017-05-03 09:04:16 +09:00
|
|
|
|
|
|
|
// Compute public path based on environment and CDN_HOST in production
|
2017-05-21 00:31:47 +09:00
|
|
|
const ifHasCDN = env.CDN_HOST !== undefined && env.NODE_ENV === 'production';
|
|
|
|
const devServerUrl = `http://${devServer.host}:${devServer.port}/${paths.entry}/`;
|
|
|
|
const publicUrl = ifHasCDN ? `${env.CDN_HOST}/${paths.entry}/` : `/${paths.entry}/`;
|
|
|
|
const publicPath = env.NODE_ENV !== 'production' ? devServerUrl : publicUrl;
|
2017-05-03 09:04:16 +09:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
devServer,
|
|
|
|
env,
|
|
|
|
paths,
|
|
|
|
loadersDir,
|
|
|
|
publicUrl,
|
2017-05-21 00:31:47 +09:00
|
|
|
publicPath,
|
|
|
|
};
|