How to use babel-loader - 10 common examples

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 Akryum / nodepack / packages / @nodepack / plugin-babel / src / index.js View on Github external
} else {
            return !!filepath.match(dep)
          }
        })) {
          return false
        }
        // Don't transpile node_modules
        return /node_modules/.test(filepath)
      })
      .end()
      .use('cache-loader')
      .loader('cache-loader')
      .options(api.genCacheConfig('babel-loader', {
        '@babel/core': require('@babel/core/package.json').version,
        '@nodepack/babel-preset-nodepack': require('@nodepack/babel-preset-nodepack/package.json').version,
        'babel-loader': require('babel-loader/package.json').version,
      }, [
        'babel.config.js',
      ]))
      .end()

    if (useThreads) {
      jsRule
        .use('thread-loader')
        .loader('thread-loader')
    }

    jsRule
      .use('babel-loader')
      .loader('babel-loader')
      .options(babelOptions)
  })
github vuejs / vue-cli / packages / @vue / cli-plugin-babel / index.js View on Github external
}

            // check if this is something the user explicitly wants to transpile
            if (transpileDepRegex && transpileDepRegex.test(filepath)) {
              return false
            }
            // Don't transpile node_modules
            return /node_modules/.test(filepath)
          })
          .end()
        .use('cache-loader')
          .loader(require.resolve('cache-loader'))
          .options(api.genCacheConfig('babel-loader', {
            '@babel/core': require('@babel/core/package.json').version,
            '@vue/babel-preset-app': require('@vue/babel-preset-app/package.json').version,
            'babel-loader': require('babel-loader/package.json').version,
            modern: !!process.env.VUE_CLI_MODERN_BUILD,
            browserslist: api.service.pkg.browserslist
          }, [
            'babel.config.js',
            '.browserslistrc'
          ]))
          .end()

    if (useThreads) {
      const threadLoaderConfig = jsRule
        .use('thread-loader')
          .loader(require.resolve('thread-loader'))

      if (typeof options.parallel === 'number') {
        threadLoaderConfig.options({ workers: options.parallel })
      }
github egoist / poi / packages / poi / lib / webpack / rules / js.js View on Github external
})
        if (shouldTranspile) {
          return true
        }
      }
      // Don't include node_modules
      return !/node_modules/.test(filepath)
    })
    .end()
    .use('babel-loader')
    .loader(require.resolve('../loaders/babel-loader'))
    .options({
      root: baseDir,
      cacheDirectory: true,
      cacheIdentifier: composeCacheIdentifiers(
        require('babel-loader/package').version,
        require('@babel/core/package').version,
        process.env.POI_JSX,
        process.env.POI_JSX_INFER,
        process.env.POI_COMMAND
      )
    })

  config.module
    .rule('coffee')
    .test(/\.coffee$/)
    .pre()
    .use('coffee-loader')
    .loader('coffee-loader')
}
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.

babel-loader

babel module loader for webpack

MIT
Latest version published 2 months ago

Package Health Score

100 / 100
Full package analysis