{"_id":"@1-week/rollup-plugin-ramda","name":"@1-week/rollup-plugin-ramda","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@1-week/rollup-plugin-ramda","version":"1.0.0","description":"Rewrite Ramda imports with Rollup for improved tree-shaking.","keywords":["ramda","rollup","rollup-plugin","vite-plugin","optimize","minify"],"homepage":"https://github.com/kyle-johnson/rollup-plugin-optimize-lodash-imports/tree/main/packages/rollup-plugin","repository":{"type":"git","url":"git+https://github.com/kyle-johnson/rollup-plugin-optimize-lodash-imports.git"},"exports":{"require":"./dist/index.js","import":"./dist/index.mjs","types":"./dist/index.d.ts"},"types":"dist/index.d.ts","author":{"name":"Kyle Johnson"},"license":"MIT","engines":{"node":">= 18"},"publishConfig":{"access":"public"},"peerDependencies":{"rollup":">= 4.x"},"devDependencies":{"@rollup/plugin-commonjs":"26.0.1","@rollup/plugin-node-resolve":"15.2.3","@rollup/plugin-terser":"0.4.4","@tsconfig/node18":"18.2.4","@types/estree":"1.0.1","@types/jest":"29.5.4","@types/ramda":"^0.30.1","@types/node":"18.15.13","@typescript-eslint/eslint-plugin":"7.18.0","@typescript-eslint/parser":"7.18.0","depcheck":"1.4.7","eslint":"8.57.0","eslint-config-prettier":"9.1.0","eslint-plugin-jest":"28.6.0","eslint-plugin-unicorn":"55.0.0","gen-esm-wrapper":"1.1.3","jest":"29.7.0","prettier":"3.3.3","prettier-2":"npm:prettier@2.8.8","ramda":"^0.30.1","rollup":"4.19.1","ts-jest":"29.1.1","ts-node":"10.9.2","typescript":"5.5.4"},"dependencies":{"@rollup/pluginutils":"^5.1.0","@1-week/ramda-transform":"1.0.0"},"scripts":{"type-check":"tsc --noEmit","lint":"eslint .","test":"jest","test:ci":"jest --coverage --ci","build":"rm -rf dist && tsc -p tsconfig.dist.json && gen-esm-wrapper ./dist ./dist/index.mjs","format":"prettier --write .","format:check":"prettier --check .","depcheck":"depcheck"},"_id":"@1-week/rollup-plugin-ramda@1.0.0","bugs":{"url":"https://github.com/kyle-johnson/rollup-plugin-optimize-lodash-imports/issues"},"_integrity":"sha512-QJs8TFGLqz6QfWHuNai1tx8yE2J3rfJPzdnlT64oZ3kttj7k1oSMcmTWTLvspu820TMoaqiQUkNprAEoT9gqEQ==","_resolved":"/private/var/folders/_w/lzw0dlfx3t9czlbj3k8f1kyh0000gn/T/53e1b46be5fdf7353e886c7d96f45b53/1-week-rollup-plugin-ramda-1.0.0.tgz","_from":"file:1-week-rollup-plugin-ramda-1.0.0.tgz","_nodeVersion":"20.16.0","_npmVersion":"10.8.1","dist":{"integrity":"sha512-QJs8TFGLqz6QfWHuNai1tx8yE2J3rfJPzdnlT64oZ3kttj7k1oSMcmTWTLvspu820TMoaqiQUkNprAEoT9gqEQ==","shasum":"d171bdc9f048e550a67996abf04535c3fec7b32e","tarball":"https://registry.npmjs.org/@1-week/rollup-plugin-ramda/-/rollup-plugin-ramda-1.0.0.tgz","fileCount":8,"unpackedSize":14469,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICtoCFZg61ivyC54tkiQ/uX6yCmJcb8Uz7Jp0dgeRdvhAiAPO6qjTyWA6LvAyblDlgOji2KcEQYtop754MEC9YsF0Q=="}]},"_npmUser":{"name":"1-week","email":"bayeszou@gmail.com"},"directories":{},"maintainers":[{"name":"1-week","email":"bayeszou@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/rollup-plugin-ramda_1.0.0_1726129419633_0.9962717602200701"},"_hasShrinkwrap":false}},"time":{"created":"2024-09-12T08:23:39.514Z","1.0.0":"2024-09-12T08:23:39.783Z","modified":"2024-09-12T08:23:40.082Z"},"maintainers":[{"name":"1-week","email":"bayeszou@gmail.com"}],"description":"Rewrite Ramda imports with Rollup for improved tree-shaking.","homepage":"https://github.com/kyle-johnson/rollup-plugin-optimize-lodash-imports/tree/main/packages/rollup-plugin","keywords":["ramda","rollup","rollup-plugin","vite-plugin","optimize","minify"],"repository":{"type":"git","url":"git+https://github.com/kyle-johnson/rollup-plugin-optimize-lodash-imports.git"},"author":{"name":"Kyle Johnson"},"bugs":{"url":"https://github.com/kyle-johnson/rollup-plugin-optimize-lodash-imports/issues"},"license":"MIT","readme":"# Optimize `lodash` imports with Rollup.js\n\n[![npm](https://img.shields.io/npm/v/@1-week/rollup-plugin-ramda)](https://www.npmjs.com/package/@1-week/rollup-plugin-ramda)\n![node-current](https://img.shields.io/node/v/@1-week/rollup-plugin-ramda)\n![npm peer dependency version](https://img.shields.io/npm/dependency-version/@1-week/rollup-plugin-ramda/peer/rollup)\n![compatible with Vite 3.x](https://img.shields.io/badge/vite-%3E%3D3.x-blue)\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/kyle-johnson/rollup-plugin-optimize-lodash-imports/main.yml?branch=main)](https://github.com/kyle-johnson/rollup-plugin-optimize-lodash-imports/actions)\n[![license](https://img.shields.io/npm/l/@1-week/rollup-plugin-ramda)](https://github.com/kyle-johnson/rollup-plugin-optimize-lodash-imports/blob/main/packages/rollup-plugin/LICENSE)\n[![Codecov](https://img.shields.io/codecov/c/github/kyle-johnson/rollup-plugin-optimize-lodash-imports?flag=rollup-plugin&label=coverage)](https://app.codecov.io/gh/kyle-johnson/rollup-plugin-optimize-lodash-imports/)\n![GitHub last commit](https://img.shields.io/github/last-commit/kyle-johnson/rollup-plugin-optimize-lodash-imports)\n\nThere are [multiple](https://github.com/webpack/webpack/issues/6925) [issues](https://github.com/lodash/lodash/issues/3839) [surrounding](https://github.com/rollup/rollup/issues/1403) [tree-shaking](https://github.com/rollup/rollup/issues/691) of lodash. Minifiers, even with dead-code elimination, cannot currently solve this problem. Check out the test showing that even with terser as a minifier, [this plugin can still reduce bundle size by 70%](https://github.com/kyle-johnson/rollup-plugin-optimize-lodash-imports/blob/main/packages/rollup-plugin/tests/bundle-size.test.ts) for [an example input](https://github.com/kyle-johnson/rollup-plugin-optimize-lodash-imports/blob/main/packages/rollup-plugin/tests/fixtures/standard-and-fp.js). With this plugin, bundled code output will _only_ include the specific lodash methods your code requires.\n\nThere is also an option to use [lodash-es](https://www.npmjs.com/package/lodash-es) for projects which ship CommonJS and ES builds: the ES build will be transformed to import from `lodash-es`.\n\nNote: versions of this plugin prior to 5.x supported NodeJS 12 and Rollup 2.x - 3.x. If you need support for these older versions, please use the 4.x release. [Rollup 4.x contains significant performance improvements](https://github.com/rollup/rollup/releases/tag/v4.0.0) over previous versions and is highly recommended.\n\n### This input\n\n```javascript\nimport { isNil, isString } from \"lodash\";\nimport { padStart as padStartFp } from \"lodash/fp\";\n```\n\n### Becomes this output\n\n```javascript\nimport isNil from \"lodash/isNil.js\";\nimport isString from \"lodash/isString.js\";\nimport padStartFp from \"lodash/fp/padStart.js\";\n```\n\n## `useLodashEs` for ES Module Output\n\nWhile `lodash-es` is not usable from CommonJS modules, some projects use Rollup to create two outputs: one for ES and one for CommonJS.\n\nIn this case, you can offer your users the best of both:\n\n### Your source input\n\n```javascript\nimport { isNil } from \"lodash\";\n```\n\n#### CommonJS output\n\n```javascript\nimport isNil from \"lodash/isNil.js\";\n```\n\n#### ES output (with `useLodashEs: true`)\n\n```javascript\nimport { isNil } from \"lodash-es\";\n```\n\n## Usage\n\n```javascript\nimport { optimizeLodashImports } from \"@1-week/rollup-plugin-ramda\";\n\nexport default {\n  input: \"src/index.js\",\n  output: {\n    dir: \"dist\",\n    format: \"cjs\",\n  },\n  plugins: [optimizeLodashImports()],\n};\n```\n\n## Options\n\nConfiguration can be passed to the plugin as an object with the following keys:\n\n### `exclude`\n\nType: `String` | `Array[...String]`<br>\nDefault: `null`\n\nA [minimatch pattern](https://github.com/isaacs/minimatch), 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 [minimatch pattern](https://github.com/isaacs/minimatch), or array of patterns, which specifies the files in the build the plugin should operate on. By default all files are targeted.\n\n### `useLodashEs`\n\nType: `boolean`<br>\nDefault: `false`\n\nIf `true`, the plugin will rewrite _lodash_ imports to use _lodash-es_.\n\n_Note: the build will fail if your Rollup output format is not also set to `es`, `esm`, or `module`!_\n\n### `appendDotJs`\n\nType: `boolean`<br>\nDefault: `true`\n\nIf `true`, the plugin will append `.js` to the end of CommonJS lodash imports.\n\nSet to `false` if you don't want the `.js` suffix added (prior to v3.x, this was the default).\n\n## Vite Compatibility\n\nThis plugin \"just works\" as a [Vite 3.x plugin](https://vitejs.dev/guide/api-plugin.html#rollup-plugin-compatibility). Simply add it to `plugins` in your [Vite config](https://vitejs.dev/config/):\n\n```javascript\nimport { defineConfig } from \"vite\";\nimport react from \"@vitejs/plugin-react\";\nimport { optimizeLodashImports } from \"@1-week/rollup-plugin-ramda\";\n\n// https://vitejs.dev/config/\nexport default defineConfig({\n  plugins: [react(), optimizeLodashImports()],\n});\n```\n\nExample Vite output for a use of [kebabCase](https://lodash.com/docs/4.17.15#kebabCase):\n\n| No plugin                                                    | With plugin                                                  |\n| ------------------------------------------------------------ | ------------------------------------------------------------ |\n| `dist/assets/index.497fb95b.js 212.88 KiB / gzip: 71.58 KiB` | `dist/assets/index.54b72c40.js 146.31 KiB / gzip: 47.81 KiB` |\n\nA ~23 KiB reduction in compressed size!\n\n## Limitations\n\n### Default imports are not optimized\n\nUnlike [babel-plugin-lodash](https://github.com/lodash/babel-plugin-lodash), there is no support for optimizing the lodash default import, such as in this case:\n\n```javascript\n// this import can't be optimized\nimport _ from \"lodash\";\n\nexport function testX(x) {\n  return _.isNil(x);\n}\n```\n\nThe above code will not be optimized, and the plugin will print a warning. (Note: Vite supresses these warnings at build time unless `--debug` is added to the build command.)\n\nTo avoid this, always import the specific method(s) you need:\n\n```javascript\n// this import will be optimized\nimport { isNil } from \"lodash\";\n\nexport function testX(x) {\n  return isNil(x);\n}\n```\n\n## Alternatives\n\n[`babel-plugin-lodash`](https://www.npmjs.com/package/babel-plugin-lodash) solves the issue for CommonJS outputs and modifies default imports as well. However, it doesn't enable transparent `lodash-es` use and may not make sense for projects using [@rollup/plugin-typescript](https://www.npmjs.com/package/@rollup/plugin-typescript) which don't wish to add a Babel step.\n\nOther alternatives include `eslint-plugin-lodash` with the [`import-scope` rule enabled](https://github.com/wix/eslint-plugin-lodash/blob/HEAD/docs/rules/import-scope.md). This works for CommonJS outputs, but may require manual effort to stay on top of imports.\n","readmeFilename":"README.md"}