Sha256: 235a5fddc57ea3a283af11e51bcd19b0242aa79559e178b99ee12e5fc24d1900

Contents?: true

Size: 858 Bytes

Versions: 3

Compression:

Stored size: 858 Bytes

Contents

/* eslint global-require: 0 */
/* eslint import/no-dynamic-require: 0 */

const { resolve } = require("path")
const { existsSync } = require("fs")
const { merge } = require("webpack-merge")

const getLoaderExtension = (filename) => {
  const matchData = filename.match(/\.([jt]sx?)?(\.erb)?$/)

  if (!matchData) {
    return "js"
  }

  return matchData[1]
}

const getCustomConfig = () => {
  const path = resolve("config", "esbuild.config.js")
  if (existsSync(path)) {
    return require(path)
  }
  return {}
}

const getEsbuildLoaderConfig = (filenameToProcess) => {
  const customConfig = getCustomConfig()
  const defaultConfig = {
    loader: require.resolve("esbuild-loader"),
    options: {
      loader: getLoaderExtension(filenameToProcess)
    }
  }

  return merge(defaultConfig, customConfig)
}

module.exports = {
  getEsbuildLoaderConfig
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
shakapacker-8.1.0 package/esbuild/index.js
shakapacker-8.0.2 package/esbuild/index.js
shakapacker-8.0.1 package/esbuild/index.js