Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@rollup/plugin-replace

Package Overview
Dependencies
Maintainers
0
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rollup/plugin-replace

Replace strings in files while bundling

  • 6.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.8M
decreased by-3.26%
Maintainers
0
Weekly downloads
 
Created

What is @rollup/plugin-replace?

The @rollup/plugin-replace npm package allows you to replace strings in files while bundling them with Rollup. This can be particularly useful for inserting environment variables, toggling between development and production modes, or any scenario where you need to dynamically alter your code at build time.

What are @rollup/plugin-replace's main functionalities?

Environment Variable Replacement

This feature allows you to replace occurrences of 'process.env.NODE_ENV' with 'production' in your code. It's particularly useful for setting the environment mode.

import replace from '@rollup/plugin-replace';

export default {
  plugins: [
    replace({
      'process.env.NODE_ENV': JSON.stringify('production')
    })
  ]
};

Conditional Code Inclusion/Exclusion

This feature enables you to conditionally include or exclude code blocks based on the replacement. In this example, all blocks guarded by 'if (process.env.DEBUG)' will always execute as if the condition is true.

import replace from '@rollup/plugin-replace';

export default {
  plugins: [
    replace({
      'if (process.env.DEBUG)': 'if (true)'
    })
  ]
};

Other packages similar to @rollup/plugin-replace

Keywords

FAQs

Package last updated on 15 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc