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.

26 lines
1.0 KiB

  1. // Common configuration for webpacker loaded from config/webpack/paths.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', 'webpack')
  7. const loadersDir = join(__dirname, 'loaders')
  8. const paths = safeLoad(readFileSync(join(configPath, 'paths.yml'), 'utf8'))[env.NODE_ENV || 'development']
  9. const devServer = safeLoad(readFileSync(join(configPath, 'development.server.yml'), 'utf8'))[env.NODE_ENV || 'development']
  10. // Compute public path based on environment and CDN_HOST in production
  11. const ifHasCDN = env.CDN_HOST !== undefined && env.NODE_ENV === 'production'
  12. const devServerUrl = `http://${devServer.host}:${devServer.port}/${paths.entry}/`
  13. const publicUrl = ifHasCDN ? `${env.CDN_HOST}/${paths.entry}/` : `/${paths.entry}/`
  14. const publicPath = env.NODE_ENV !== 'production' ? devServerUrl : publicUrl
  15. module.exports = {
  16. devServer,
  17. env,
  18. paths,
  19. loadersDir,
  20. publicUrl,
  21. publicPath
  22. }