How to use the babel-loader.custom function in babel-loader

To help you get started, we’ve selected a few babel-loader examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github saberland / saber / packages / saber / src / webpack / babel-loader.js View on Github external
const path = require('path')
const babelLoader = require('babel-loader')
const { log } = require('saber-log')
const logUpdate = require('log-update')

// increment '0' to invalidate cache
const CACHE_KEY = `babel-cache-0`

module.exports = babelLoader.custom(babel => {
  const configs = new Set()

  return {
    customOptions(opts) {
      const custom = opts.customLoaderOptions
      const filename = path.join(custom.cwd, 'noop.js')
      const loader = Object.assign(
        custom.shouldCache
          ? {
              cacheCompression: false,
              cacheDirectory: path.join(
                custom.distDir,
                'cache',
                'saber-babel-loader'
              ),
              cacheIdentifier: JSON.stringify({
github gourmetjs / gourmet-ssr / builder / webpack-babel / lib / custom-babel-loader.js View on Github external
"use strict";

const npath = require("path");

// Provides `configPath` option to `@babel/preset-env` so it can find
// a browserslist's config file based on source file's location.
module.exports = require("babel-loader").custom(babel => {
  return {
    config(cfg) {
      let options = cfg.options;

      const presets = options.presets;

      for (let idx = 0; presets && idx < presets.length; idx++) {
        const item = presets[idx];
        if (item.name === "@babel/preset-env") {
          options = Object.assign({}, options, {
            presets: [].concat(
              presets.slice(0, idx),
              babel.createConfigItem(
                [
                  require.resolve("@babel/preset-env"),
                  Object.assign({}, item.options, {
github zeit / next.js / packages / next / build / webpack / loaders / next-babel-loader.js View on Github external
// Blacklist accidental inclusions
    'transform-regenerator',
    'transform-async-to-generator',
  ]

  return {
    ...babelOptions,
    'preset-env': presetEnvOptions,
    'transform-runtime': transformRuntimeOptions,
  }
}

const nextBabelPresetModern = presetOptions => context =>
  nextBabelPreset(context, getModernOptions(presetOptions))

module.exports = babelLoader.custom(babel => {
  const presetItem = babel.createConfigItem(nextBabelPreset, {
    type: 'preset',
  })
  const applyCommonJs = babel.createConfigItem(
    require('../../babel/plugins/commonjs'),
    { type: 'plugin' }
  )
  const commonJsItem = babel.createConfigItem(
    require('@babel/plugin-transform-modules-commonjs'),
    { type: 'plugin' }
  )

  const configs = new Set()

  return {
    customOptions(opts) {
github egoist / poi / core / poi / lib / webpack / babel-loader.js View on Github external
const babelLoader = require('babel-loader')
const logger = require('@poi/logger')
const spinner = require('../utils/spinner')

const macroCheck = new RegExp('[./]macro')

module.exports = babelLoader.custom(babel => {
  const configs = new Set()
  const presetItem = babel.createConfigItem(require('../babel/preset'), {
    type: 'preset'
  })

  return {
    customOptions(opts) {
      const custom = opts.customLoaderOptions
      delete opts.customLoaderOptions

      return { loader: opts, custom }
    },
    config(cfg, { source }) {
      const options = Object.assign({}, cfg.options, {
        caller: Object.assign({}, cfg.options.caller, {
          // for babel-plugin-macros it should never be cached
github GiancarlosIO / webpack-nexus / packages / nexus-scripts / lib / webpack / configurations / custom-babel-loader.js View on Github external
module.exports = require('babel-loader').custom(() => ({
  config(cfg) {
    return {
      ...cfg.options,
      presets: [
        ...(cfg.options.presets || []),
        // eslint-disable-next-line global-require
        require('babel-preset-webpack-nexus'),
      ],
    };
  },
}));
github smooth-code / smooth.js / packages / smooth / src / webpack / loaders / smooth-babel-loader.js View on Github external
/* eslint-disable prefer-object-spread */
/* eslint-disable no-restricted-syntax */
import babelLoader from 'babel-loader'
import preset from '../../babel/preset'

module.exports = babelLoader.custom(babel => {
  const presetItem = babel.createConfigItem(preset, {
    type: 'preset',
  })

  const configs = new Set()

  return {
    customOptions(opts) {
      const custom = {
        isServer: opts.isServer,
        dev: opts.dev,
      }

      const loader = Object.assign(
        {
          cacheCompression: false,
github cmux / koot / packages / koot-webpack / loaders / babel / index.js View on Github external
const transformFixDefaultExport = require('./transform-fix-default-export');

module.exports = require('babel-loader').custom(babel => {
    // function myPlugin() {
    //     return {
    //         visitor: {},
    //     };
    // }
    const customOptions = {};

    return {
        // Passed the loader options.
        customOptions({ __createDll, __react, __typescript, ...loader }) {
            Object.assign(customOptions, {
                __createDll,
                __react,
                __typescript
            });
            // Pull out any custom options that the loader might have.
github egoist / poi / packages / poi / lib / webpack / loaders / babel-loader.js View on Github external
const babelLoader = require('babel-loader')
const logger = require('@poi/cli-utils/logger')

const macroCheck = new RegExp('[./]macro')

module.exports = babelLoader.custom(babel => {
  const presetItem = babel.createConfigItem(require('../../babel/preset'), {
    type: 'preset'
  })
  const configs = new Set()

  return {
    customOptions(opts) {
      const custom = opts.customLoaderOptions
      delete opts.customLoaderOptions

      return { loader: opts, custom }
    },
    config(cfg, { source }) {
      const options = Object.assign({}, cfg.options, {
        caller: Object.assign({}, cfg.options.caller, {
          // for babel-plugin-macros it should never be cached
github lnlfps / symph-joy / build / webpack / loaders / joy-babel-loader.js View on Github external
import babelLoader from 'babel-loader'

module.exports = babelLoader.custom(babel => {
  const presetItem = babel.createConfigItem(require('../../babel/preset'), { type: 'preset' })

  const configs = new Set()

  return {
    customOptions (opts) {
      const custom = {
        isServer: opts.isServer,
        dev: opts.dev
      }
      const loader = Object.assign({
        cacheDirectory: true
      }, opts)
      delete loader.isServer
      delete loader.dev

babel-loader

babel module loader for webpack

MIT
Latest version published 2 months ago

Package Health Score

100 / 100
Full package analysis