How to use the babel-loader/package.json.version 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 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 kentcdodds / glamorous-website / next.config.js View on Github external
/* eslint import/no-extraneous-dependencies:0 */
const fs = require('fs')
const marked = require('marked')

const renderer = new marked.Renderer()
const {LOCALE} = process.env

renderer.heading = (text, level) => {
  const escapedText = text.toLowerCase().replace(/[^\w]+/g, '-')

  return `<a href="#${escapedText}" name="${escapedText}">${text}</a>`
}

const cacheIdentifier = JSON.stringify({
  'babel-loader': require('babel-loader/package.json').version,
  'babel-core': require('babel-core/package.json').version,
  babelrc: fs.readFileSync('./.babelrc', 'utf8'),
  env: process.env.BABEL_ENV || process.env.NODE_ENV || 'development',
  locale: process.env.LOCALE,
})

module.exports = {
  distDir: `dist/${LOCALE || 'dev'}`,
  webpack: config =&gt; {
    config.module.rules.forEach(rule =&gt; {
      if (rule.loader === 'babel-loader') {
        if (process.env.DISABLE_CACHE) {
          rule.options.cacheDirectory = false
        } else {
          rule.options.cacheIdentifier = cacheIdentifier
        }
github mapbox / underreact / lib / webpack-config / babel-loader-config.js View on Github external
function createCacheIdentifier({ urc, babelConfig = '' }) {
  return JSON.stringify({
    'babel-loader': require('babel-loader/package.json').version,
    '@babel/core': require('@babel/core/package.json').version,
    'babel-preset-mapbox': require('@mapbox/babel-preset-mapbox').version,
    babelConfig,
    env: process.env.BABEL_ENV || process.env.NODE_ENV || 'development',
    // Use `browserslist` module to do finding of the config and parse it.
    // Note, this would also work when a user uses `urc.browserslist`
    // since we would set it as env var `BROWSERSLIST` and `browserslist`
    // module will then read it.
    browserslist: browserslist(null, {
      path: urc.rootDirectory,
      env: process.env.NODE_ENV === 'production' ? 'production' : 'development'
    })
  });
}
github frontity / frontity / packages / core / src / config / webpack / modules.ts View on Github external
// Support for js, jsx, ts and tsx files.
        test: /\.(j|t)sx?$/,
        use: {
          loader: "babel-loader",
          options: {
            // Don't use the babelrc file of the root.
            babelrc: false,
            // This is a feature of `babel-loader` for webpack (not Babel itself).
            // It enables caching results in ./node_modules/.cache/babel-loader/
            // directory for faster rebuilds.
            cacheDirectory: true,
            // A unique hash using @babel/core's version, the babel-loader's version,
            // and the contents of babel.
            cacheIdentifier: hash({
              babelCoreVersion: babelCore.version,
              babelLoaderVersion: babelLoader.version,
              babel: babel
            }),
            // Instead, use the babel options directly from our babel object.
            ...babel[target]
          }
        }
      },
      {
        test: /\.(png|jpe?g|gif|svg)$/,
        use: [
          {
            loader: "file-loader",
            options: {
              name: (file: string): string => {
                const filename = /([^/\\]+)\.(?:png|jpe?g|gif|svg)$/.exec(
                  file
github mapbox / underreact / lib / webpack-helpers / create-webpack-config.js View on Github external
const babelrcPath = path.join(urc.rootDirectory, '.babelrc');
  const exists = fs.existsSync(babelrcPath);
  const loader = {
    loader: require.resolve('babel-loader'),
    options: {
      presets: [require('../../packages/babel-preset-mapbox')],
      babelrc: false,
      compact: false,
      cacheDirectory: true,
      cacheCompression: urc.production,
      // `babel-preset-mapbox` depends on the `process.env.BROWSERSLIST` and
      // any change in its value would fail to change the default `cacheIdentifier` of `babel-loader`
      // hence leading to stale babel output. To mitigate this we need to create a more accurate `cacheIdentifier`
      // which is (`defaultCacheIdentifier` + `urc.browserslist`) ref: https://github.com/babel/babel-loader/blob/7.x/src/index.js#L129
      cacheIdentifier: JSON.stringify({
        'babel-loader': require('babel-loader/package.json').version,
        'babel-core': require('babel-core/package.json').version,
        babelrc: exists ? fs.readFileSync(babelrcPath, 'utf8') : '',
        env: process.env.BABEL_ENV || process.env.NODE_ENV || 'development',
        browserslist: urc.browserslist
      })
    }
  };

  if (exists) {
    delete loader.options.presets;
    loader.options.babelrc = true;
  }

  return loader;
}

babel-loader

babel module loader for webpack

MIT
Latest version published 3 months ago

Package Health Score

97 / 100
Full package analysis