{"_id":"swc-plugin-transform-import","_rev":"245042","name":"swc-plugin-transform-import","description":"swc plugin for transforming import path to optimize bundle size","dist-tags":{"latest":"1.2.0"},"maintainers":[{"name":"ankitchouhan1020","email":"ankitchouhan1020@gmail.com"}],"time":{"modified":"2023-03-27T06:46:25.000Z","created":"2022-02-05T11:30:37.957Z","1.2.0":"2022-03-08T09:32:41.878Z","1.1.2":"2022-02-22T16:42:04.491Z","1.0.2":"2022-02-05T16:59:48.811Z","1.0.1":"2022-02-05T14:21:57.274Z","1.0.0":"2022-02-05T11:30:37.957Z"},"users":{},"author":{"name":"Ankit Chouhan"},"repository":{"type":"git","url":"git+https://github.com/ankitchouhan1020/swc-plugin-transform-import.git"},"versions":{"1.2.0":{"name":"swc-plugin-transform-import","version":"1.2.0","description":"swc plugin for transforming import path to optimize bundle size","main":"lib/index.js","scripts":{"test":"tsc && mocha"},"repository":{"type":"git","url":"git+https://github.com/ankitchouhan1020/swc-plugin-transform-import.git"},"bugs":{"url":"https://github.com/ankitchouhan1020/swc-plugin-transform-import/issues"},"homepage":"https://github.com/ankitchouhan1020/swc-plugin-transform-import#readme","author":{"name":"Ankit Chouhan"},"license":"ISC","devDependencies":{"@tsconfig/node16":"^1.0.2","@types/node":"^17.0.15","expect":"^27.5.0","mocha":"^9.2.0","typescript":"^4.5.5"},"dependencies":{"@swc/core":"^1.2.136"},"gitHead":"49960be1e6c7a677e8115f0ce577b814415db80c","_id":"swc-plugin-transform-import@1.2.0","_nodeVersion":"16.13.2","_npmVersion":"8.1.2","dist":{"shasum":"ad1a049a89134baff39f11dd4be6981e5bcf24ed","size":3767,"noattachment":false,"key":"/swc-plugin-transform-import/-/swc-plugin-transform-import-1.2.0.tgz","tarball":"http://name.csiicloud.com:7001/swc-plugin-transform-import/download/swc-plugin-transform-import-1.2.0.tgz"},"_npmUser":{"name":"ankitchouhan1020","email":"ankitchouhan1020@gmail.com"},"directories":{},"maintainers":[{"name":"ankitchouhan1020","email":"ankitchouhan1020@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/swc-plugin-transform-import_1.2.0_1646731961543_0.011637029353253059"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-03-08T09:33:29.759Z","publish_time":1646731961878,"_cnpm_publish_time":1646731961878},"1.1.2":{"name":"swc-plugin-transform-import","version":"1.1.2","description":"swc plugin for transforming import path to optimize bundle size","main":"lib/index.js","scripts":{"test":"tsc && mocha"},"repository":{"type":"git","url":"git+https://github.com/ankitchouhan1020/swc-plugin-transform-import.git"},"bugs":{"url":"https://github.com/ankitchouhan1020/swc-plugin-transform-import/issues"},"homepage":"https://github.com/ankitchouhan1020/swc-plugin-transform-import#readme","author":{"name":"Ankit Chouhan"},"license":"ISC","devDependencies":{"@tsconfig/node16":"^1.0.2","@types/node":"^17.0.15","expect":"^27.5.0","mocha":"^9.2.0","typescript":"^4.5.5"},"dependencies":{"@swc/core":"^1.2.136"},"gitHead":"c3025001e6254734d4b3abbf4705bc0e13eb986b","_id":"swc-plugin-transform-import@1.1.2","_nodeVersion":"16.13.2","_npmVersion":"8.1.2","dist":{"shasum":"25ce0e8773edc7d0171f048324e07dc0df339bed","size":3703,"noattachment":false,"key":"/swc-plugin-transform-import/-/swc-plugin-transform-import-1.1.2.tgz","tarball":"http://name.csiicloud.com:7001/swc-plugin-transform-import/download/swc-plugin-transform-import-1.1.2.tgz"},"_npmUser":{"name":"ankitchouhan1020","email":"ankitchouhan1020@gmail.com"},"directories":{},"maintainers":[{"name":"ankitchouhan1020","email":"ankitchouhan1020@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/swc-plugin-transform-import_1.1.2_1645548124302_0.10928521229286425"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-02-22T16:42:07.888Z","publish_time":1645548124491,"_cnpm_publish_time":1645548124491},"1.0.2":{"name":"swc-plugin-transform-import","version":"1.0.2","description":"swc plugin for transforming import path to optimize bundle size","main":"lib/index.js","scripts":{"test":"tsc && mocha"},"repository":{"type":"git","url":"git+https://github.com/ankitchouhan1020/swc-plugin-transform-import.git"},"bugs":{"url":"https://github.com/ankitchouhan1020/swc-plugin-transform-import/issues"},"homepage":"https://github.com/ankitchouhan1020/swc-plugin-transform-import#readme","author":{"name":"Ankit Chouhan"},"license":"ISC","devDependencies":{"@tsconfig/node16":"^1.0.2","@types/node":"^17.0.15","expect":"^27.5.0","mocha":"^9.2.0","typescript":"^4.5.5"},"dependencies":{"@swc/core":"^1.2.136"},"gitHead":"7b6e6c6c0dabb9b78ddafdb4263a45b77e90280a","_id":"swc-plugin-transform-import@1.0.2","_nodeVersion":"16.13.2","_npmVersion":"8.1.2","dist":{"shasum":"dd1a6b133f214b98ce2966ec0a5f0be992929924","size":3539,"noattachment":false,"key":"/swc-plugin-transform-import/-/swc-plugin-transform-import-1.0.2.tgz","tarball":"http://name.csiicloud.com:7001/swc-plugin-transform-import/download/swc-plugin-transform-import-1.0.2.tgz"},"_npmUser":{"name":"ankitchouhan1020","email":"ankitchouhan1020@gmail.com"},"directories":{},"maintainers":[{"name":"ankitchouhan1020","email":"ankitchouhan1020@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/swc-plugin-transform-import_1.0.2_1644080388669_0.1392144076873667"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-02-05T16:59:53.426Z","publish_time":1644080388811,"_cnpm_publish_time":1644080388811},"1.0.1":{"name":"swc-plugin-transform-import","version":"1.0.1","description":"swc plugin for transforming import path to optimize bundle size","main":"lib/index.js","scripts":{"test":"tsc && mocha"},"author":{"name":"Ankit Chouhan"},"license":"ISC","devDependencies":{"@tsconfig/node16":"^1.0.2","@types/node":"^17.0.15","expect":"^27.5.0","mocha":"^9.2.0","typescript":"^4.5.5"},"dependencies":{"@swc/core":"^1.2.136"},"gitHead":"dd39fee75bbd2f05f839efb5cb107c94626dfe9e","_id":"swc-plugin-transform-import@1.0.1","_nodeVersion":"16.13.2","_npmVersion":"8.1.2","dist":{"shasum":"4c937e1bc776102edfd9f407879c0963221e11cd","size":3300,"noattachment":false,"key":"/swc-plugin-transform-import/-/swc-plugin-transform-import-1.0.1.tgz","tarball":"http://name.csiicloud.com:7001/swc-plugin-transform-import/download/swc-plugin-transform-import-1.0.1.tgz"},"_npmUser":{"name":"ankitchouhan1020","email":"ankitchouhan1020@gmail.com"},"directories":{},"maintainers":[{"name":"ankitchouhan1020","email":"ankitchouhan1020@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/swc-plugin-transform-import_1.0.1_1644070917113_0.4015875613576678"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-02-05T14:22:01.677Z","publish_time":1644070917274,"_cnpm_publish_time":1644070917274},"1.0.0":{"name":"swc-plugin-transform-import","version":"1.0.0","description":"swc plugin for transforming import path to optimize bundle size","main":"lib/index.js","scripts":{"test":"tsc && mocha"},"author":{"name":"Ankit Chouhan"},"license":"ISC","devDependencies":{"@tsconfig/node16":"^1.0.2","@types/node":"^17.0.15","expect":"^27.5.0","mocha":"^9.2.0","typescript":"^4.5.5"},"dependencies":{"@swc/core":"^1.2.136"},"gitHead":"7db36def3782fe601b4905971cf2b222fe1588d4","_id":"swc-plugin-transform-import@1.0.0","_nodeVersion":"16.13.2","_npmVersion":"8.1.2","dist":{"shasum":"ddcfdcec6cc8647c26d3b57dc3495ab847ac3826","size":4269,"noattachment":false,"key":"/swc-plugin-transform-import/-/swc-plugin-transform-import-1.0.0.tgz","tarball":"http://name.csiicloud.com:7001/swc-plugin-transform-import/download/swc-plugin-transform-import-1.0.0.tgz"},"_npmUser":{"name":"ankitchouhan1020","email":"ankitchouhan1020@gmail.com"},"directories":{},"maintainers":[{"name":"ankitchouhan1020","email":"ankitchouhan1020@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/swc-plugin-transform-import_1.0.0_1644060637819_0.6478805651312818"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-02-05T11:30:42.619Z","publish_time":1644060637957,"_cnpm_publish_time":1644060637957}},"readme":"# swc-plugin-transform-import\nInspired from [babel-plugin-transform-imports](https://www.npmjs.com/package/babel-plugin-transform-imports)\n\n## Installation\n\n```bash\nnpm i -D swc-plugin-transform-import\n```\n\n## Uses with webpack-config\n```javascript\n// webpack.config.js\n\nconst PluginTransformImport = require('swc-plugin-transform-import').default;\n\nmodule: {\n    rules: [\n      {\n        test: /\\.(ts|tsx|js|jsx)$/,\n        exclude: /node_modules/,\n        use: [{\n          loader: 'swc-loader',\n          options: {\n            plugin: (m) => new PluginTransformImport({\n              \"lodash\": {\n                \"transform\": \"lodash/${member}\",\n                \"preventFullImport\": true\n              }\n            }).visitProgram(m),\n          }\n        }]\n      },\n    ],\n};\n\n```\n\n\n```javascript\nimport { Row, Grid as MyGrid } from 'react-bootstrap';\nimport { merge } from 'lodash';\n```\n\n...into default style imports:\n\n```javascript\nimport Row from 'react-bootstrap/lib/Row';\nimport MyGrid from 'react-bootstrap/lib/Grid';\nimport merge from 'lodash/merge';\n```\n\n*Note: this plugin is not restricted to the react-bootstrap and lodash\nlibraries.  You may use it with any library.*\n\n## That's stupid, why would you do that?\n\nWhen SWC encounters a member style import such as:\n\n```javascript\nimport { Grid, Row, Col } from 'react-bootstrap';\n```\n\nit will generate something similarish to:\n\n```javascript\nvar reactBootstrap = require('react-bootstrap');\nvar Grid = reactBootstrap.Grid;\nvar Row = reactBootstrap.Row;\nvar Col = reactBootstrap.Col;\n```\n\nSome libraries, such as react-bootstrap and lodash, are rather large and\npulling in the entire module just to use a few pieces would cause unnecessary\nbloat to your client optimized (webpack etc.) bundle.  The only way around\nthis is to use default style imports:\n\n```javascript\nimport Grid from 'react-bootstrap/lib/Grid';\nimport Row from 'react-bootstrap/lib/Row';\nimport Col from 'react-bootstrap/lib/Col';\n```\n\nBut, the more pieces we need, the more this sucks.  This plugin will allow you\nto pull in just the pieces you need, without a separate import for each item.\nAdditionally, it can be configured to throw when somebody accidentally writes\nan import which would cause the entire module to resolve, such as:\n\n```javascript\nimport Bootstrap, { Grid } from 'react-bootstrap';\n// -- or --\nimport * as Bootstrap from 'react-bootstrap';\n```\n\n## Installation\n\n```\nnpm install --save-dev swc-plugin-transform-import\n```\n\n\n## Advanced Transformations\n\nIn cases where the provided default string replacement transformation is not\nsufficient (for example, needing to execute a RegExp on the import name), you\nmay instead provide a path to a .js file which exports a function to run\ninstead.  Keep in mind that the .js file will be `require`d relative from this\nplugin's path, likely located in `/node_modules/babel-plugin-transform-imports`.\nYou may provide any filename, as long as it ends with `.js`.\n\n.babelrc:\n```json\n{\n    \"plugins\": [\n        [\"transform-imports\", {\n            \"my-library\": {\n                \"transform\": \"../../path/to/transform.js\",\n                \"preventFullImport\": true\n            }\n        }]\n    ]\n}\n```\n\n/path/to/transform.js:\n```js\nmodule.exports = function(importName) {\n    return 'my-library/etc/' + importName.toUpperCase();\n};\n```\n\n## Options\n\n| Name | Type | Required | Default | Description |\n| --- | --- | --- | --- | --- |\n| `transform` | `string` | yes | `undefined` | The library name to use instead of the one specified in the import statement.  ${member} will be replaced with the member, aka Grid/Row/Col/etc.  Alternatively, pass a path to a .js file which exports a function to process the transform (see Advanced Transformations) |\n| `preventFullImport` | `boolean` | no | `false` | Whether or not to throw when an import is encountered which would cause the entire module to be imported. |\n| `skipDefaultConversion` | `boolean` | no | `false` | When set to true, will preserve `import { X }` syntax instead of converting to `import X`. |\n| `style` | `boolean` or `function` | no | `false` | When set to true, will add side effect import of transformed path concatenated with `/style`. When set as a function, receive an argument as the transformed path, return the tramsformed style module path |\n","_attachments":{},"homepage":"https://github.com/ankitchouhan1020/swc-plugin-transform-import#readme","bugs":{"url":"https://github.com/ankitchouhan1020/swc-plugin-transform-import/issues"},"license":"ISC"}