{"name":"@rollup/plugin-replace","version":"6.0.2","keywords":["rollup","plugin","replace","es2015","npm","modules"],"author":{"name":"Rich Harris","email":"richard.a.harris@gmail.com"},"license":"MIT","_id":"@rollup/plugin-replace@6.0.2","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"}],"homepage":"https://github.com/rollup/plugins/tree/master/packages/replace#readme","bugs":{"url":"https://github.com/rollup/plugins/issues"},"ava":{"files":["!**/fixtures/**","!**/helpers/**","!**/recipes/**","!**/types.ts"],"workerThreads":false},"dist":{"shasum":"2f565d312d681e4570ff376c55c5c08eb6f1908d","tarball":"http://registry-npm.ywwl.com/@rollup/plugin-replace/download/@rollup/plugin-replace-6.0.2.tgz","fileCount":8,"integrity":"sha512-7QaYCf8bqF04dOy7w/eHmJeNExxTYwvKAmlSAH/EaWWUzbT0h5sbF6bktFoX/0F/0qwng5/dWFMyf3gzaM8DsQ==","signatures":[{"sig":"MEUCIFbNsEeI5wtxtmwj8HCWgc2NUzjVDwJ72Z3YenVVTh7HAiEA9XkglDppqmEZzHwZQuMsn1+I/uIHcgNgbHi93IonUtY=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":23613,"size":6332,"noattachment":false,"key":"/@rollup/plugin-replace/-/@rollup/plugin-replace-6.0.2.tgz"},"main":"dist/cjs/index.js","_from":"file:rollup-plugin-replace-6.0.2.tgz","types":"./types/index.d.ts","module":"dist/es/index.js","engines":{"node":">=14.0.0"},"exports":{"types":"./types/index.d.ts","import":"./dist/es/index.js","default":"./dist/cjs/index.js"},"scripts":{"test":"ava","build":"rollup -c","ci:lint":"pnpm build && pnpm lint","ci:test":"pnpm test -- --verbose && pnpm test:ts","pretest":"pnpm build","release":"pnpm --workspace-root package:release $(pwd)","test:ts":"tsc types/index.d.ts test/types.ts --noEmit","prebuild":"del-cli dist","prerelease":"pnpm build","ci:coverage":"nyc pnpm test && nyc report --reporter=text-lcov > coverage.lcov","ci:lint:commits":"commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}"},"_npmUser":{"name":"shellscape","email":"andrew@shellscape.org"},"_resolved":"/tmp/bbe27d5cb86cba0269d9a0508ad941b0/rollup-plugin-replace-6.0.2.tgz","_integrity":"sha512-7QaYCf8bqF04dOy7w/eHmJeNExxTYwvKAmlSAH/EaWWUzbT0h5sbF6bktFoX/0F/0qwng5/dWFMyf3gzaM8DsQ==","repository":{"url":"git+https://github.com/rollup/plugins.git","directory":"packages/replace"},"_npmVersion":"10.8.2","description":"Replace strings in files while bundling","directories":{},"_nodeVersion":"20.18.1","dependencies":{"magic-string":"^0.30.3","@rollup/pluginutils":"^5.0.1"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"rollup":"^4.0.0-24","del-cli":"^5.0.0","source-map":"^0.7.4","typescript":"^4.8.3","locate-character":"^2.0.5","@rollup/plugin-buble":"^1.0.0"},"peerDependencies":{"rollup":"^1.20.0||^2.0.0||^3.0.0||^4.0.0"},"peerDependenciesMeta":{"rollup":{"optional":true}},"_npmOperationalInternal":{"tmp":"tmp/plugin-replace_6.0.2_1734278789794_0.2427283760119323","host":"s3://npm-registry-packages-npm-production"},"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":1734278789955,"_cnpm_publish_time":1734278789955,"dist-tags":{"latest":"6.0.3"}}