Sha256: 04c18a994339a995f7021ef60e8fcb8b3e7a55032f44c97f911656d81f9bbad0

Contents?: true

Size: 1.64 KB

Versions: 14

Compression:

Stored size: 1.64 KB

Contents

const shakapackerDevServerYamlConfig = require('./dev_server')
const snakeToCamelCase = require('./utils/snakeToCamelCase')
const { outputPath: contentBase, publicPath } = require('./config')

const webpackDevServerMappedKeys = new Set([
  // client, server, liveReload, devMiddleware are handled separately
  'allowedHosts',
  'bonjour',
  'compress',
  'headers',
  'historyApiFallback',
  'host',
  'hot',
  'http2',
  'https',
  'ipc',
  'magicHtml',
  'onAfterSetupMiddleware',
  'onBeforeSetupMiddleware',
  'open',
  'port',
  'proxy',
  'server',
  'setupExitSignals',
  'setupMiddlewares',
  'watchFiles',
  'webSocketServer'
])

function createDevServerConfig() {
  const devServerYamlConfig = { ...shakapackerDevServerYamlConfig }
  const liveReload = devServerYamlConfig.live_reload !== undefined ? devServerYamlConfig.live_reload : !devServerYamlConfig.hmr
  delete devServerYamlConfig.live_reload

  const config = {
    devMiddleware: {
      publicPath
    },
    liveReload,
    historyApiFallback: {
      disableDotRule: true
    },
    static: {
      publicPath: contentBase
    }
  }

  if (devServerYamlConfig.static) {
    config.static = { ...config.static, ...devServerYamlConfig.static }
    delete devServerYamlConfig.static
  }

  if (devServerYamlConfig.client) {
    config.client = devServerYamlConfig.client
    delete devServerYamlConfig.client
  }

  Object.keys(devServerYamlConfig).forEach((yamlKey) => {
    const camelYamlKey = snakeToCamelCase(yamlKey)
    if (webpackDevServerMappedKeys.has(camelYamlKey)) {
      config[camelYamlKey] = devServerYamlConfig[yamlKey]
    }
  })

  return config
}

module.exports = createDevServerConfig

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
shakapacker-7.2.3 package/webpackDevServerConfig.js
shakapacker-7.3.0.beta.1 package/webpackDevServerConfig.js
shakapacker-7.2.2 package/webpackDevServerConfig.js
shakapacker-7.2.1 package/webpackDevServerConfig.js
shakapacker-7.2.0 package/webpackDevServerConfig.js
shakapacker-7.2.0.rc.0 package/webpackDevServerConfig.js
shakapacker-7.1.0 package/webpackDevServerConfig.js
shakapacker-7.0.3 package/webpackDevServerConfig.js
shakapacker-7.0.2 package/webpackDevServerConfig.js
shakapacker-7.0.1 package/webpackDevServerConfig.js
shakapacker-7.0.0 package/webpackDevServerConfig.js
shakapacker-7.0.0.rc.2 package/webpackDevServerConfig.js
shakapacker-7.0.0.rc.1 package/webpackDevServerConfig.js
shakapacker-7.0.0.rc.0 package/webpackDevServerConfig.js