How to use @rollup/plugin-replace - 10 common examples

To help you get started, we’ve selected a few @rollup/plugin-replace 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 Azure / azure-sdk-for-js / sdk / core / core-auth / rollup.base.config.js View on Github external
export function browserConfig(test = false) {
  const baseConfig = {
    input: input,
    output: {
      file: "browser/core-auth.js",
      format: "umd",
      name: "Azure.Core.Auth",
      sourcemap: true
    },
    preserveSymlinks: false,
    plugins: [
      sourcemaps(),
      replace({
        delimiters: ["", ""],
        values: {
          // replace dynamic checks with if (false) since this is for
          // browser only. Rollup's dead code elimination will remove
          // any code guarded by if (isNode) { ... }
          "if (isNode)": "if (false)"
        }
      }),
      nodeResolve({
        mainFields: ['module', 'browser'],
        preferBuiltins: false
      }),
      cjs({
        namedExports: { events: ["EventEmitter"] }
      }),
      viz({ filename: "browser/browser-stats.html", sourcemap: false })
github vuejs / vue-next / rollup.config.js View on Github external
__BUNDLER__: isBundlerESMBuild,
    // support compile in browser?
    __RUNTIME_COMPILE__: isRuntimeCompileBuild,
    // support options?
    // the lean build drops options related code with buildOptions.lean: true
    __FEATURE_OPTIONS__: !packageOptions.lean && !process.env.LEAN,
    __FEATURE_SUSPENSE__: true
  }
  // allow inline overrides like
  //__RUNTIME_COMPILE__=true yarn build runtime-core
  Object.keys(replacements).forEach(key => {
    if (key in process.env) {
      replacements[key] = process.env[key]
    }
  })
  return replace(replacements)
}
github Azure / azure-sdk-for-js / sdk / eventhub / event-hubs / rollup.base.config.js View on Github external
export function nodeConfig(test = false) {
  const externalNodeBuiltins = ["events", "util", "os"];
  const baseConfig = {
    input: input,
    external: depNames.concat(externalNodeBuiltins),
    output: { file: "dist/index.js", format: "cjs", sourcemap: true },
    preserveSymlinks: false,
    plugins: [
      sourcemaps(),
      replace({
        delimiters: ["", ""],
        values: {
          // replace dynamic checks with if (true) since this is for node only.
          // Allows rollup's dead code elimination to be more aggressive.
          "if (isNode)": "if (true)"
        }
      }),
      nodeResolve({ preferBuiltins: true }),
      cjs(),
      json()
    ]
  };

  baseConfig.external.push("crypto");

  if (test) {
github Azure / azure-sdk-for-js / sdk / keyvault / keyvault-certificates / rollup.base.config.js View on Github external
file: "browser/azure-keyvault-certificates.js",
      banner: banner,
      format: "umd",
      name: "azurekeyvaultcertificates",
      globals: {
        "@azure/core-http": "Azure.Core.HTTP",
        "@azure/core-arm": "Azure.Core.ARM",
        "@azure/keyvault-keys": "Azure.KeyVault.Keys",
        "@azure/keyvault-secrets": "Azure.KeyVault.Secrets"
      },
      sourcemap: true
    },
    preserveSymlinks: false,
    plugins: [
      sourcemaps(),
      replace({
        delimiters: ["", ""],
        values: {
          // replace dynamic checks with if (false) since this is for
          // browser only. Rollup's dead code elimination will remove
          // any code guarded by if (isNode) { ... }
          "if (isNode)": ";isNode; if (false)"
        }
      }),
      // os is not used by the browser bundle, so just shim it
      shim({
        dotenv: `export function config() { }`,
        os: `
          export const type = 1;
          export const release = 1;
        `
      }),
github Azure / azure-sdk-for-js / sdk / storage / storage-file-datalake / rollup.base.config.js View on Github external
export function browserConfig(test = false) {
  const baseConfig = {
    input: "dist-esm/src/index.browser.js",
    output: {
      file: "browser/azure-storage-file-datalake.js",
      banner: banner,
      format: "umd",
      name: "azdatalake",
      sourcemap: true
    },
    preserveSymlinks: false,
    plugins: [
      sourcemaps(),
      replace({
        delimiters: ["", ""],
        values: {
          // replace dynamic checks with if (false) since this is for
          // browser only. Rollup's dead code elimination will remove
          // any code guarded by if (isNode) { ... }
          "if (isNode)": "if (false)"
        }
      }),
      // fs and os are not used by the browser bundle, so just shim it
      // dotenv doesn't work in the browser, so replace it with a no-op function
      shim({
        dotenv: `export function config() { }`,
        fs: `
          export function stat() { }
          export function createReadStream() { }
          export function createWriteStream() { }
github jaredpalmer / tsdx / src / createRollupConfig.ts View on Github external
},
        check: opts.transpileOnly === false,
      }),
      babelPluginTsdx({
        exclude: 'node_modules/**',
        extensions: [...DEFAULT_EXTENSIONS, 'ts', 'tsx'],
        passPerPreset: true,
        custom: {
          targets: opts.target === 'node' ? { node: '8' } : undefined,
          extractErrors: opts.extractErrors,
          format: opts.format,
          // defines: opts.defines,
        },
      }),
      opts.env !== undefined &&
        replace({
          'process.env.NODE_ENV': JSON.stringify(opts.env),
        }),
      sourceMaps(),
      // sizeSnapshot({
      //   printInfo: false,
      // }),
      shouldMinify &&
        terser({
          sourcemap: true,
          output: { comments: false },
          compress: {
            keep_infinity: true,
            pure_getters: true,
            passes: 10,
          },
          ecma: 5,
github Azure / azure-sdk-for-js / sdk / storage / storage-file-datalake / rollup.base.config.js View on Github external
"os",
    "stream",
    "util"
  ];
  const baseConfig = {
    input: "dist-esm/src/index.js",
    external: depNames.concat(externalNodeBuiltins),
    output: {
      file: "dist/index.js",
      format: "cjs",
      sourcemap: true
    },
    preserveSymlinks: false,
    plugins: [
      sourcemaps(),
      replace({
        delimiters: ["", ""],
        values: {
          // replace dynamic checks with if (true) since this is for node only.
          // Allows rollup's dead code elimination to be more aggressive.
          "if (isNode)": "if (true)"
        }
      }),
      nodeResolve({ preferBuiltins: true }),
      cjs({
        namedExports: {
          events: ["EventEmitter"],
          assert: [
            "ok",
            "deepEqual",
            "equal",
            "fail",
github Azure / azure-sdk-for-js / sdk / core / core-amqp / rollup.base.config.js View on Github external
export function browserConfig(test = false) {
  const baseConfig = {
    input: input,
    output: {
      file: "browser/index.js",
      format: "umd",
      name: "Azure.AMQPCommon",
      sourcemap: true
    },
    preserveSymlinks: false,
    plugins: [
      sourcemaps(),

      replace({
        delimiters: ["", ""],
        values: {
          // replace dynamic checks with if (false) since this is for
          // browser only. Rollup's dead code elimination will remove
          // any code guarded by if (isNode) { ... }
          "if (isNode)": "if (false)"
        }
      }),

      // fs, net, and tls are used by rhea and need to be shimmed
      // TODO: get these into rhea's pkg.browser field
      // dotenv doesn't work in the browser, so replace it with a no-op function
      shim({
        fs: `export default {}`,
        net: `export default {}`,
        tls: `export default {}`,
github Azure / azure-sdk-for-js / sdk / core / logger / rollup.base.config.js View on Github external
export function browserConfig(test = false) {
  const baseConfig = {
    input: input,
    external: ["ms-rest-js"],
    output: {
      file: "browser/logger.js",
      format: "umd",
      name: "Azure.Logger",
      sourcemap: true
    },
    preserveSymlinks: false,
    plugins: [
      sourcemaps(),
      replace(
        // ms-rest-js is externalized so users must include it prior to using this bundle.
        {
          delimiters: ["", ""],
          values: {
            // replace dynamic checks with if (false) since this is for
            // browser only. Rollup's dead code elimination will remove
            // any code guarded by if (isNode) { ... }
            "if (isNode)": "if (false)"
          }
        }
      ),
      nodeResolve({
        mainFields: ["module", "browser"],
        preferBuiltins: false
      }),
      cjs({
github gpbl / react-day-picker / package / rollup.config.js View on Github external
const input = "./src/index.ts";
const globals = { react: "React" };
const external = Object.keys(globals);

const typescriptPlugin = typescript({
  rollupCommonJSResolveHack: true,
  clean: true,
  verbosity: 2
});
const aliasPlugin = alias({
  resolve: ["*.ts", "*.tsx"],
  entries: {
    components: path.resolve("./src/components")
  }
});
const replaceProduction = replace({
  "process.env.NODE_ENV": JSON.stringify("production")
});

export default [
  {
    input,
    output: {
      file: "lib/index.umd.js",
      format: "umd",
      name,
      globals,
      sourcemap: true
    },
    external,
    plugins: [nodeResolve(), typescriptPlugin]
  },

@rollup/plugin-replace

Replace strings in files while bundling

MIT
Latest version published 6 months ago

Package Health Score

97 / 100
Full package analysis

Popular @rollup/plugin-replace functions