Sha256: 12a34dcd6496815b6cf716f4908a2a4ca4cafd4c0bd3bf9759a41809d1130e2e

Contents?: true

Size: 1.75 KB

Versions: 20

Compression:

Stored size: 1.75 KB

Contents

const { resolve } = require('path')
const { safeLoad } = require('js-yaml')
const { readFileSync } = require('fs')
const deepMerge = require('./utils/deep_merge')
const { isArray, ensureTrailingSlash } = require('./utils/helpers')
const { railsEnv } = require('./env')

const defaultConfigPath = require.resolve('../lib/install/config/webpacker.yml')
const configPath = resolve('config', 'webpacker.yml')

const getDefaultConfig = () => {
  const defaultConfig = safeLoad(readFileSync(defaultConfigPath), 'utf8')
  return defaultConfig[railsEnv] || defaultConfig.production
}

const defaults = getDefaultConfig()
const app = safeLoad(readFileSync(configPath), 'utf8')[railsEnv]

if (isArray(app.extensions) && app.extensions.length) delete defaults.extensions
if (isArray(app.static_assets_extensions) && app.static_assets_extensions.length) {
  delete defaults.static_assets_extensions
}

const config = deepMerge(defaults, app)
config.outputPath = resolve(config.public_root_path, config.public_output_path)

// Ensure that the publicPath includes our asset host so dynamic imports
// (code-splitting chunks and static assets) load from the CDN instead of a relative path.
const getPublicPath = () => {
  const rootUrl = process.env.WEBPACKER_ASSET_HOST || '/'
  let packPath = `${config.public_output_path}/`
  // Add relative root prefix to pack path.
  if (process.env.RAILS_RELATIVE_URL_ROOT) {
    let relativeRoot = process.env.RAILS_RELATIVE_URL_ROOT
    relativeRoot = relativeRoot.startsWith('/') ? relativeRoot.substr(1) : relativeRoot
    packPath = `${ensureTrailingSlash(relativeRoot)}${packPath}`
  }

  return ensureTrailingSlash(rootUrl) + packPath
}

config.publicPath = getPublicPath()
config.publicPathWithoutCDN = `/${config.public_output_path}/`

module.exports = config

Version data entries

20 entries across 20 versions & 5 rubygems

Version Path
disco_app-0.18.0 test/dummy/node_modules/@rails/webpacker/package/config.js
disco_app-0.18.2 test/dummy/node_modules/@rails/webpacker/package/config.js
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/webpacker-4.0.7/package/config.js
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/webpacker-4.0.7/package/config.js
jester-data-8.0.0 node_modules/@rails/webpacker/package/config.js
ezii-os-5.2.1 node_modules/@rails/webpacker/package/config.js
ezii-os-2.0.1 node_modules/@rails/webpacker/package/config.js
ezii-os-1.1.0 node_modules/@rails/webpacker/package/config.js
ezii-os-1.0.0 node_modules/@rails/webpacker/package/config.js
ezii-os-0.0.0.1.0 node_modules/@rails/webpacker/package/config.js
ezii-os-0.0.0.0.1 node_modules/@rails/webpacker/package/config.js
webpacker-4.0.7 package/config.js
webpacker-4.0.6 package/config.js
webpacker-4.0.5 package/config.js
webpacker-4.0.4 package/config.js
webpacker-4.0.3 package/config.js
webpacker-4.0.2 package/config.js
webpacker-4.0.1 package/config.js
webpacker-4.0.0 package/config.js
webpacker-4.0.0.rc.8 package/config.js