Sha256: fb4fe6ad311acdea1d0ae9d8343d0a0bc0e85c1a28f13d197c03f72c9e724373

Contents?: true

Size: 1.2 KB

Versions: 28

Compression:

Stored size: 1.2 KB

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 isJsxFile = (filename) => !!filename.match(/\.(jsx|tsx)?(\.erb)?$/)

const isTypescriptFile = (filename) => !!filename.match(/\.(ts|tsx)?(\.erb)?$/)

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

const getSwcLoaderConfig = (filenameToProcess) => {
  const customConfig = getCustomConfig()
  const defaultConfig = {
    loader: require.resolve('swc-loader'),
    options: {
      jsc: {
        parser: {
          dynamicImport: true,
          syntax: isTypescriptFile(filenameToProcess)
            ? 'typescript'
            : 'ecmascript',
          [isTypescriptFile(filenameToProcess) ? 'tsx' : 'jsx']:
            isJsxFile(filenameToProcess)
        },
        loose: true
      },
      sourceMaps: true,
      env: {
        coreJs: 3,
        exclude: ['transform-typeof-symbol'],
        mode: 'entry'
      }
    }
  }

  return merge(defaultConfig, customConfig)
}

module.exports = {
  getSwcLoaderConfig
}

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
shakapacker-7.2.3 package/swc/index.js
shakapacker-7.3.0.beta.1 package/swc/index.js
shakapacker-7.2.2 package/swc/index.js
shakapacker-7.2.1 package/swc/index.js
shakapacker-7.2.0 package/swc/index.js
shakapacker-7.2.0.rc.0 package/swc/index.js
shakapacker-7.1.0 package/swc/index.js
shakapacker-7.0.3 package/swc/index.js
shakapacker-7.0.2 package/swc/index.js
shakapacker-7.0.1 package/swc/index.js
shakapacker-7.0.0 package/swc/index.js
shakapacker-7.0.0.rc.2 package/swc/index.js
shakapacker-7.0.0.rc.1 package/swc/index.js
shakapacker-7.0.0.rc.0 package/swc/index.js
shakapacker-6.6.0 package/swc/index.js
shakapacker-6.5.6 package/swc/index.js
shakapacker-6.5.5 package/swc/index.js
shakapacker-6.5.4 package/swc/index.js
shakapacker-6.5.3 package/swc/index.js
shakapacker-6.5.2 package/swc/index.js