コード例 #1
0
function makeExample(name) {
  return {
    experimentalCodeSplitting: true,
    input: path.join(__dirname, 'examples', 'src', name, 'main.js'),
    external: ['rebound'],
    output: {
      file: path.join(__dirname, 'examples', 'dist', name + '.js'),
      format: 'iife',
      globals: {
        rebound: 'rebound',
      },
      banner: `
  /**
   *  Copyright (c) 2013, Facebook, Inc.
   *  All rights reserved.
   *
   *  This source code is licensed under the BSD-style license found in the
   *  LICENSE file in the root directory of this source tree. An additional grant
   *  of patent rights can be found in the PATENTS file in the same directory.
   */
        `.trim(),
    },
    plugins: [
      babel({
        plugins: ['external-helpers'],
        exclude: 'node_modules/**',
      }),
      stripBanner({
        exclude: 'node_modules/**/*',
        sourceMap: true,
      }),
    ],
  };
}
コード例 #2
0
ファイル: build.js プロジェクト: Pioneer-Linzi/react
function getPlugins(
  entry,
  externals,
  updateBabelOptions,
  filename,
  packageName,
  bundleType,
  globalName,
  moduleType,
  modulesToStub
) {
  const findAndRecordErrorCodes = extractErrorCodes(errorCodeOpts);
  const forks = Modules.getForks(bundleType, entry, moduleType);
  const isProduction = isProductionBundleType(bundleType);
  const isProfiling = isProfilingBundleType(bundleType);
  const isUMDBundle = bundleType === UMD_DEV || bundleType === UMD_PROD;
  const isFBBundle =
    bundleType === FB_WWW_DEV ||
    bundleType === FB_WWW_PROD ||
    bundleType === FB_WWW_PROFILING;
  const isRNBundle =
    bundleType === RN_OSS_DEV ||
    bundleType === RN_OSS_PROD ||
    bundleType === RN_OSS_PROFILING ||
    bundleType === RN_FB_DEV ||
    bundleType === RN_FB_PROD ||
    bundleType === RN_FB_PROFILING;
  const shouldStayReadable = isFBBundle || isRNBundle || forcePrettyOutput;
  return [
    // Extract error codes from invariant() messages into a file.
    shouldExtractErrors && {
      transform(source) {
        findAndRecordErrorCodes(source);
        return source;
      },
    },
    // Shim any modules that need forking in this environment.
    useForks(forks),
    // Ensure we don't try to bundle any fbjs modules.
    blacklistFBJS(),
    // Use Node resolution mechanism.
    resolve({
      skip: externals,
    }),
    // Remove license headers from individual modules
    stripBanner({
      exclude: 'node_modules/**/*',
    }),
    // Compile to ES5.
    babel(getBabelConfig(updateBabelOptions, bundleType)),
    // Remove 'use strict' from individual source files.
    {
      transform(source) {
        return source.replace(/['"]use strict['"']/g, '');
      },
    },
    // Turn __DEV__ and process.env checks into constants.
    replace({
      __DEV__: isProduction ? 'false' : 'true',
      __PROFILE__: isProfiling || !isProduction ? 'true' : 'false',
      'process.env.NODE_ENV': isProduction ? "'production'" : "'development'",
    }),
    // We still need CommonJS for external deps like object-assign.
    commonjs(),
    // www still needs require('React') rather than require('react')
    isFBBundle && {
      transformBundle(source) {
        return source
          .replace(/require\(['"]react['"]\)/g, "require('React')")
          .replace(/require\(['"]react-is['"]\)/g, "require('ReactIs')");
      },
    },
    // Apply dead code elimination and/or minification.
    isProduction &&
      closure(
        Object.assign({}, closureOptions, {
          // Don't let it create global variables in the browser.
          // https://github.com/facebook/react/issues/10909
          assume_function_wrapper: !isUMDBundle,
          // Works because `google-closure-compiler-js` is forked in Yarn lockfile.
          // We can remove this if GCC merges my PR:
          // https://github.com/google/closure-compiler/pull/2707
          // and then the compiled version is released via `google-closure-compiler-js`.
          renaming: !shouldStayReadable,
        })
      ),
    // Add the whitespace back if necessary.
    shouldStayReadable && prettier({parser: 'babylon'}),
    // License and haste headers, top-level `if` blocks.
    {
      transformBundle(source) {
        return Wrappers.wrapBundle(
          source,
          bundleType,
          globalName,
          filename,
          moduleType
        );
      },
    },
    // Record bundle size.
    sizes({
      getSize: (size, gzip) => {
        const currentSizes = Stats.currentBuildResults.bundleSizes;
        const recordIndex = currentSizes.findIndex(
          record =>
            record.filename === filename && record.bundleType === bundleType
        );
        const index = recordIndex !== -1 ? recordIndex : currentSizes.length;
        currentSizes[index] = {
          filename,
          bundleType,
          packageName,
          size,
          gzip,
        };
      },
    }),
  ].filter(Boolean);
}
コード例 #3
0
ファイル: rollup.conf.js プロジェクト: mjeanroy/jasmine-utils
const stripBanner = require('rollup-plugin-strip-banner');
const license = require('rollup-plugin-license');
const esformatter = require('rollup-plugin-esformatter');
const config = require('../config.js');

module.exports = {
  input: config.entry,
  output: {
    file: config.dest,
    format: 'iife',
    sourcemap: false,
  },

  plugins: [
    // Remove banner from single modules.
    stripBanner(),

    // Transform code to old JavaScript.
    babel(),

    // Prepend banner.
    license({
      banner: {
        file: path.join(config.root, 'LICENSE'),
      },
    }),

    // Beautify bundle.
    esformatter({
      sourcemap: false,
    }),
コード例 #4
0
import fs from 'fs';
import path from 'path';
import buble from 'rollup-plugin-buble';
import commonjs from 'rollup-plugin-commonjs';
import stripBanner from 'rollup-plugin-strip-banner';

const copyright = fs.readFileSync(path.join('resources', 'COPYRIGHT'), 'utf-8');

const SRC_DIR = path.resolve('src');
const DIST_DIR = path.resolve('dist');

export default {
  format: 'es',
  exports: 'named',
  sourceMap: false,
  banner: copyright,
  moduleName: 'Immutable',
  entry: path.join(SRC_DIR, 'Immutable.js'),
  dest: path.join(DIST_DIR, 'immutable.es.js'),
  plugins: [commonjs(), stripBanner(), buble()]
};