{"name":"@rollup/plugin-replace","version":"6.0.3","publishConfig":{"access":"public"},"description":"Replace strings in files while bundling","license":"MIT","repository":{"url":"git+https://github.com/rollup/plugins.git","directory":"packages/replace"},"author":{"name":"Rich Harris","email":"richard.a.harris@gmail.com"},"homepage":"https://github.com/rollup/plugins/tree/master/packages/replace#readme","bugs":{"url":"https://github.com/rollup/plugins/issues"},"main":"dist/cjs/index.js","module":"dist/es/index.js","exports":{"types":"./types/index.d.ts","import":"./dist/es/index.js","default":"./dist/cjs/index.js"},"engines":{"node":">=14.0.0"},"keywords":["rollup","plugin","replace","es2015","npm","modules"],"peerDependencies":{"rollup":"^1.20.0||^2.0.0||^3.0.0||^4.0.0"},"peerDependenciesMeta":{"rollup":{"optional":true}},"dependencies":{"@rollup/pluginutils":"^5.0.1","magic-string":"^0.30.3"},"devDependencies":{"@rollup/plugin-buble":"^1.0.0","del-cli":"^5.0.0","locate-character":"^2.0.5","rollup":"^4.0.0-24","source-map":"^0.7.4","typescript":"^4.8.3"},"types":"./types/index.d.ts","ava":{"workerThreads":false,"files":["!**/fixtures/**","!**/helpers/**","!**/recipes/**","!**/types.ts"]},"scripts":{"build":"rollup -c","ci:coverage":"nyc pnpm test && nyc report --reporter=text-lcov > coverage.lcov","ci:lint":"pnpm build && pnpm lint","ci:lint:commits":"commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}","ci:test":"pnpm test -- --verbose && pnpm test:ts","prebuild":"del-cli dist","prerelease":"pnpm build","pretest":"pnpm build","release":"pnpm --workspace-root package:release $(pwd)","test":"ava","test:ts":"tsc types/index.d.ts test/types.ts --noEmit"},"_id":"@rollup/plugin-replace@6.0.3","_integrity":"sha512-J4RZarRvQAm5IF0/LwUUg+obsm+xZhYnbMXmXROyoSE1ATJe3oXSb9L5MMppdxP2ylNSjv6zFBwKYjcKMucVfA==","_resolved":"/tmp/1c404525e01ea7f76299e49d28edca09/rollup-plugin-replace-6.0.3.tgz","_from":"file:rollup-plugin-replace-6.0.3.tgz","_nodeVersion":"20.19.5","_npmVersion":"10.8.2","dist":{"integrity":"sha512-J4RZarRvQAm5IF0/LwUUg+obsm+xZhYnbMXmXROyoSE1ATJe3oXSb9L5MMppdxP2ylNSjv6zFBwKYjcKMucVfA==","shasum":"0f82e41d81f6586ab0f81a1b48bd7fd92fcfb9a2","tarball":"http://registry-npm.ywwl.com/@rollup/plugin-replace/download/@rollup/plugin-replace-6.0.3.tgz","fileCount":8,"unpackedSize":23925,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQD9/wyWh3NBK8J2Eq5MWdZyLiMrReTBFTBFLUt0CmP3VAIhALQ+dnrPS5JGRTk43j7+a1mHq2O4w+SKkm40pYYGiudy"}],"size":6378,"noattachment":false,"key":"/@rollup/plugin-replace/-/@rollup/plugin-replace-6.0.3.tgz"},"_npmUser":{"name":"shellscape","email":"andrew@shellscape.org"},"directories":{},"maintainers":[{"name":"shellscape","email":"andrew@shellscape.org"},{"name":"rich_harris","email":"richard.a.harris@gmail.com"},{"name":"guybedford","email":"guybedford@gmail.com"},{"name":"lukastaegert","email":"lukas.taegert@tngtech.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/plugin-replace_6.0.3_1761744123866_0.1420691110766077"},"_hasShrinkwrap":false,"readme":"[npm]: https://img.shields.io/npm/v/@rollup/plugin-replace\n[npm-url]: https://www.npmjs.com/package/@rollup/plugin-replace\n[size]: https://packagephobia.now.sh/badge?p=@rollup/plugin-replace\n[size-url]: https://packagephobia.now.sh/result?p=@rollup/plugin-replace\n\n[![npm][npm]][npm-url]\n[![size][size]][size-url]\n[![libera manifesto](https://img.shields.io/badge/libera-manifesto-lightgrey.svg)](https://liberamanifesto.com)\n\n# @rollup/plugin-replace\n\n🍣 A Rollup plugin which replaces targeted strings in files while bundling.\n\n## Requirements\n\nThis plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v14.0.0+) and Rollup v1.20.0+.\n\n## Install\n\nUsing npm:\n\n```console\nnpm install @rollup/plugin-replace --save-dev\n```\n\n## Usage\n\nCreate a `rollup.config.js` [configuration file](https://www.rollupjs.org/guide/en/#configuration-files) and import the plugin:\n\n```js\nimport replace from '@rollup/plugin-replace';\n\nexport default {\n  input: 'src/index.js',\n  output: {\n    dir: 'output',\n    format: 'cjs'\n  },\n  plugins: [\n    replace({\n      'process.env.NODE_ENV': JSON.stringify('production'),\n      __buildDate__: () => JSON.stringify(new Date()),\n      __buildVersion: 15\n    })\n  ]\n};\n```\n\nThen call `rollup` either via the [CLI](https://www.rollupjs.org/guide/en/#command-line-reference) or the [API](https://www.rollupjs.org/guide/en/#javascript-api).\n\nThe configuration above will replace every instance of `process.env.NODE_ENV` with `\"production\"` and `__buildDate__` with the result of the given function in any file included in the build.\n\n_Note: Values must be either primitives (e.g. string, number) or `function` that returns a string. For complex values, use `JSON.stringify`. To replace a target with a value that will be evaluated as a string, set the value to a quoted string (e.g. `\"test\"`) or use `JSON.stringify` to preprocess the target string safely._\n\nTypically, `@rollup/plugin-replace` should be placed in `plugins` _before_ other plugins so that they may apply optimizations, such as dead code removal.\n\n## Options\n\nIn addition to the properties and values specified for replacement, users may also specify the options below.\n\n### `delimiters`\n\nType: `Array[String, String]`<br>\nDefault: `['(?<![_$a-zA-Z0-9\\\\xA0-\\\\uFFFF])', '(?![_$a-zA-Z0-9\\\\xA0-\\\\uFFFF])(?!\\\\.)']`\n\nSpecifies the boundaries around which strings will be replaced. By default, delimiters match JavaScript identifier boundaries and also prevent replacements of instances with nested access. See [Word Boundaries](#word-boundaries) below for more information.\nFor example, if you pass `typeof window` in `values` to-be-replaced, then you could expect the following scenarios:\n\n- `typeof window` **will** be replaced\n- `typeof window.document` **will not** be replaced due to the `(?!\\.)` boundary\n- `typeof windowSmth` **will not** be replaced due to identifier boundaries\n\nDelimiters will be used to build a `Regexp`. To match special characters (any of `.*+?^${}()|[]\\`), be sure to [escape](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping) them.\n\n### `objectGuards`\n\nType: `Boolean`<br>\nDefault: `false`\n\nWhen replacing dot-separated object properties like `process.env.NODE_ENV`, will also replace `typeof process` object guard\nchecks against the objects with the string `\"object\"`.\n\nFor example:\n\n```js\nreplace({\n  values: {\n    'process.env.NODE_ENV': '\"production\"'\n  }\n});\n```\n\n```js\n// Input\nif (typeof process !== 'undefined' && process.env.NODE_ENV === 'production') {\n  console.log('production');\n}\n// Without `objectGuards`\nif (typeof process !== 'undefined' && 'production' === 'production') {\n  console.log('production');\n}\n// With `objectGuards`\nif ('object' !== 'undefined' && 'production' === 'production') {\n  console.log('production');\n}\n```\n\n### `preventAssignment`\n\nType: `Boolean`<br>\nDefault: `false`\n\nPrevents replacing strings where they are followed by a single equals sign. For example, where the plugin is called as follows:\n\n```js\nreplace({\n  values: {\n    'process.env.DEBUG': 'false'\n  }\n});\n```\n\nObserve the following code:\n\n```js\n// Input\nprocess.env.DEBUG = false;\nif (process.env.DEBUG == true) {\n  //\n}\n// Without `preventAssignment`\nfalse = false; // this throws an error because false cannot be assigned to\nif (false == true) {\n  //\n}\n// With `preventAssignment`\nprocess.env.DEBUG = false;\nif (false == true) {\n  //\n}\n```\n\n### `exclude`\n\nType: `String` | `Array[...String]`<br>\nDefault: `null`\n\nA [picomatch pattern](https://github.com/micromatch/picomatch), or array of patterns, which specifies the files in the build the plugin should _ignore_. By default no files are ignored.\n\n### `include`\n\nType: `String` | `Array[...String]`<br>\nDefault: `null`\n\nA [picomatch pattern](https://github.com/micromatch/picomatch), or array of patterns, which specifies the files in the build the plugin should operate on. By default all files are targeted.\n\n### `sourceMap` or `sourcemap`\n\nType: `Boolean`<br>\nDefault: `false`\n\nEnables generating sourcemaps for the bundled code. For example, where the plugin is called as follows:\n\n```js\nreplace({\n  sourcemap: true\n});\n```\n\n### `values`\n\nType: `{ [key: String]: Replacement }`, where `Replacement` is either a string or a `function` that returns a string.\nDefault: `{}`\n\nTo avoid mixing replacement strings with the other options, you can specify replacements in the `values` option. For example, the following signature:\n\n```js\nreplace({\n  include: ['src/**/*.js'],\n  changed: 'replaced'\n});\n```\n\nCan be replaced with:\n\n```js\nreplace({\n  include: ['src/**/*.js'],\n  values: {\n    changed: 'replaced'\n  }\n});\n```\n\n## Word Boundaries\n\nBy default, values will only match if they are surrounded by _word boundaries_ that respect JavaScript's rules for valid identifiers (including `$` and `_` as valid identifier characters).\n\nConsider the following options and build file:\n\n```js\nmodule.exports = {\n  ...\n  plugins: [replace({ changed: 'replaced' })]\n};\n```\n\n```js\n// file.js\nconsole.log('changed');\nconsole.log('unchanged');\n```\n\nThe result would be:\n\n```js\n// file.js\nconsole.log('replaced');\nconsole.log('unchanged');\n```\n\nTo ignore word boundaries and replace every instance of the string, wherever it may be, specify empty strings as delimiters:\n\n```js\nexport default {\n  ...\n  plugins: [\n    replace({\n      changed: 'replaced',\n      delimiters: ['', '']\n    })\n  ]\n};\n```\n\n## Meta\n\n[CONTRIBUTING](/.github/CONTRIBUTING.md)\n\n[LICENSE (MIT)](/LICENSE)\n","publish_time":1761744124097,"_cnpm_publish_time":1761744124097,"dist-tags":{"latest":"6.0.3"}}