Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/bs / src / .plugins / typescript.ts
Size: Mime:
/**
 * @todo https://github.com/TypeStrong/ts-loader/blob/master/examples/happypack/webpack.config.js
 */
import HappyPack from 'happypack'
import { resolveToRoot } from '../resolveToRoot'
import { Configuration, Options } from '../typings'
import babel from './typescriptBabel'

const TYPESCRIPT_ENV = true
/**
 * @@pnp @note - does not work with pnp yet but can turn off
 * @todo no need for happypack on build prod?
 */
// process.env.PNP === undefined
const IS_HAPPYPACK_ENABLED = false

let happypackPlugin
function getHappy() {
  if (happypackPlugin) {
    return happypackPlugin
  }
  console.log('getHappy')

  const happypackConfig = {
    id: 'ts',
    threads: 2,
    loaders: [
      {
        path: 'ts-loader',
        query: {
          happyPackMode: true,
        },
      },
    ],
  }
  const plugin = new HappyPack(happypackConfig)
  happypackPlugin = plugin
  return happypackPlugin
}

export default function typescriptPlugin(
  config: Configuration,
  options: Options
) {
  if (TYPESCRIPT_ENV && !IS_HAPPYPACK_ENABLED) {
    // const pathsToTranspile = options.bundleConfig.srcPaths.map(resolveToRoot)

    const typescriptLoader = {
      test: /\.(tsx|ts|jsx|js)$/,
      exclude: /(node_modules)/,
      // exclude: /node_modules(?!\/\@skava\/ui)/,
      // include: pathsToTranspile,

      use: [
        {
          /**
           * @see https://github.com/Microsoft/TypeScriptSamples/blob/master/react-flux-babel-karma/webpack.config.js
           * @see https://github.com/amireh/happypack/issues/32
           */
          loader: require.resolve('babel-loader'),
          options: {
            ...babel(config, options),
            // false if debugging
            // cacheDirectory: false,
            cacheDirectory: true,
          },
        },
        {
          /**
           * @see https://webpack.js.org/guides/build-performance/#typescript-loader
           * @see https://github.com/TypeStrong/ts-loader#ignorediagnostics-number-default
           */
          loader: require.resolve('ts-loader'),
          options: {
            // disable type checker - we will use it in fork plugin
            transpileOnly: true,
            experimentalWatchApi: true,
          },
        },
      ],
    }

    config.module.rules.unshift(typescriptLoader)
  }

  if (process.env.SHOULD_BUILD_CHECK_STRICT_TYPESCRIPT) {
    const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
    const checker = new ForkTsCheckerWebpackPlugin()
    config.plugins.push(checker)
  }
}