{"_id":"@avensia-oss/ts-transform-import-to-lazy-async-import","_rev":"7-c9ae9b4758cce3f9cc6f4636692dec90","name":"@avensia-oss/ts-transform-import-to-lazy-async-import","dist-tags":{"latest":"0.0.3"},"versions":{"0.0.1":{"name":"@avensia-oss/ts-transform-import-to-lazy-async-import","version":"0.0.1","keywords":["TypeScript","transform","transformer","react","import","lazy"],"author":{"name":"Anders Ekdahl","email":"anders.ekdahl@avensia.com"},"license":"MIT","_id":"@avensia-oss/ts-transform-import-to-lazy-async-import@0.0.1","maintainers":[{"name":"avensia-oss","email":"andekd@avensia.com"}],"homepage":"https://github.com/avensia-oss/ts-transform-import-to-react-lazy","bugs":{"url":"https://github.com/avensia-oss/ts-transform-import-to-react-lazy"},"dist":{"shasum":"dac43a76dfce7b98aa42d4035eb3f412b374ca4d","tarball":"https://registry.npmjs.org/@avensia-oss/ts-transform-import-to-lazy-async-import/-/ts-transform-import-to-lazy-async-import-0.0.1.tgz","fileCount":9,"integrity":"sha512-GfRA/PRxnGUYoIwF+GGcOuhbsgoZ769Oc+FRcSHpFsMHmpX0CczpDQOmu3Mx9AqnmJnV38Xie/Poaq0aIjys8w==","signatures":[{"sig":"MEUCIF2ExF3KW6sxAMmG+LQqVX1YfM+Y6mPBnFet5mQbZ80kAiEAyCWLBAly39vYm9xlROkp1Aj0mHu4taUSryZ8XtKc3CM=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":20318,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcL2NACRA9TVsSAnZWagAA7VIP/jl/6u8IEEPwmRIr0feT\nqRboirNp7cX+RlZFpucrVpUaoFDxi+GEvYoiFeaxMui6aUeivFsSD21KkdH6\nxZzA4wdKVnZg2vBJXFNhGQ2SrkuNBL54Xlp/ojyljdrx8iKPX9zfqpxLOZEh\n0KNno8pdRgdnfz7WBtRMLqPB1CILh+zaFAndnohpAff57sE0ymwZKPb0YD9x\ndz9W7BSJypA21HAlwOf4g3lGG4mIPb0biUHJ8B2H5Vobbg7BrYTRSGZXQCa1\nhP7jQp2CQjXYKqS+SNRCRC2kscqpZymu5/t/QujZbiluFToQ30sJZNndiMw2\nYQUGgS6+T5znv5T0/45ajVFyfFNUKbxE3PoQrQ/c9pZAnN7vY8t5csXvjtZW\nMUQhOdR/n371muao3QDDnlLfW8Wl+Sf9F7gu9QktPia6QXFpUF9d5Qa34XFI\neep3320eGxHov6YGGECD6grKqaaCJLp7D6wHnH9ozTYK/0PP0ef5HObpZflN\n8lvUOcWKLzdS9pczqKVGfoEaac6vH6NE0WuSjWrHLcSMFUu15fI95eWmm1NN\n4xdc20/+EhWkKxDl3/WGojg6Gp5K6g5WEk8HViVK0rw9A+bFzO7Q7U3rQjF8\n4ZgZL7kwFw3fgH2Y476Sctctc68i6tD63blzkyp3hDxw4dOwbgw3V2bv5a1Y\nVwgr\r\n=4ULr\r\n-----END PGP SIGNATURE-----\r\n"},"main":"index.js","private":false,"scripts":{"test":"jest","build":"tsc --version && tsc --project \"./\""},"_npmUser":{"name":"avensia-oss","email":"andekd@avensia.com"},"description":"A TypeScript custom transformer that rewrites synchronously loaded React components to async, lazy loaded components","directories":{},"licenseText":"MIT License\n\nCopyright (c) Avensia AB and its affiliates.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.","dependencies":{"@types/react":"^16.7.18"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^23.6.0","ts-jest":"^23.10.5","ts-node":"^7.0.1","prettier":"^1.15.3","typescript":"^3.2.2","@types/jest":"^23.3.10","@types/node":"^10.12.18"},"peerDependencies":{"typescript":"*"},"_npmOperationalInternal":{"tmp":"tmp/ts-transform-import-to-lazy-async-import_0.0.1_1546609472075_0.6110823017245939","host":"s3://npm-registry-packages"}},"0.0.2":{"name":"@avensia-oss/ts-transform-import-to-lazy-async-import","version":"0.0.2","keywords":["TypeScript","transform","transformer","react","import","lazy"],"author":{"name":"Anders Ekdahl","email":"anders.ekdahl@avensia.com"},"license":"MIT","_id":"@avensia-oss/ts-transform-import-to-lazy-async-import@0.0.2","maintainers":[{"name":"avensia-oss","email":"andekd@avensia.com"}],"homepage":"https://github.com/avensia-oss/ts-transform-import-to-react-lazy","bugs":{"url":"https://github.com/avensia-oss/ts-transform-import-to-react-lazy"},"dist":{"shasum":"43d08d5407bc82cc0fea419133fc878bbd2da28b","tarball":"https://registry.npmjs.org/@avensia-oss/ts-transform-import-to-lazy-async-import/-/ts-transform-import-to-lazy-async-import-0.0.2.tgz","fileCount":6,"integrity":"sha512-KPbWfynt6WLC9NphWSgyJ3571lZ+MElave7yLHz0SQOp3gKMS08U5LcjkoWKMls3nIQK/Uc6R8fVvIjGyVUCww==","signatures":[{"sig":"MEYCIQD1xJCm6UzMtLKyvLs0sgsuI83o/pMTKqDwDZfLT3OrNwIhAMl1j3h4BkUfCHYD2SZ3UoUuvG1WOvdEx6MQfZLZpTgD","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":7592,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJctz0CCRA9TVsSAnZWagAA55kP+QGQrU/7BU/Va4XU45Wv\no41IYG8lbBaJRD/Wf6UfBq83NITMxIcIsYlrH7ykp4bP2lGk+gmXCGeWM1pv\notU1Q09QljncUCEcC+m5MDxe2K/FN2ml+YOvdn8941dWGDVmETKOM7aWinzu\nFuNjU9bvcZ5pZs5ULHAe78pZ+k3JlC6JypPeY9mOCNdx9gISk5sCydBCbdUf\ngBBZgOGJJGjOll/0SnKtWS0XeAp4dXua+Oz91any5g/ng9qZPFTsBCPTBFU3\nERlACtvcqubavy5GbvQCS7iu5/j+i3p+7qu9vTE2vw4I83qCDCAtgKVA0C0y\ns5MclPdTDRvuSqbROdQzvv8gQodnHMxdXgS1Y+QZiJZBZbhxiBOiVuUx/zKV\nxc6q/DdyDZZbW/gQpaUW4DNDvl9c6OtFow8GoUzXbPwin6ILhC9uDUq88aYq\nnunIzKGsHr7BQaPJryGr4qhjhGFmsAlEtB76xcX3KL1uzONIOXOboLUH/Igk\n1dRGIhnltvZ2B63O1/HAgYjpG0858Pt1O8pWiboFxnhbqQV40PPD2ZUiwcjq\ng530Bb16G8H+lSXaJEOqMwX5HrCOjcWfHPst477KuueXqoJPpmJQXAsSbFOq\niS1WQURaITJiNpyEX0QNHC60Osm3B1SDlmxznGo4VC0DHPn6BxYR7USZlng+\n+ChD\r\n=VXnj\r\n-----END PGP SIGNATURE-----\r\n"},"main":"index.js","types":"dist/src/index.d.ts","private":false,"scripts":{"test":"jest","build":"tsc --version && tsc --project \"./\""},"_npmUser":{"name":"avensia-oss","email":"andekd@avensia.com"},"description":"A TypeScript custom transformer that rewrites synchronously loaded React components to async, lazy loaded components","directories":{},"licenseText":"MIT License\n\nCopyright (c) Avensia AB and its affiliates.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.","dependencies":{"@types/react":"^16.7.18"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^23.6.0","ts-jest":"^23.10.5","ts-node":"^7.0.1","prettier":"^1.15.3","typescript":"^3.2.2","@types/jest":"^23.3.10","@types/node":"^10.12.18"},"peerDependencies":{"typescript":"*"},"_npmOperationalInternal":{"tmp":"tmp/ts-transform-import-to-lazy-async-import_0.0.2_1555512577554_0.8176944417626086","host":"s3://npm-registry-packages"}},"0.0.3":{"name":"@avensia-oss/ts-transform-import-to-lazy-async-import","version":"0.0.3","keywords":["TypeScript","transform","transformer","react","import","lazy"],"author":{"name":"Anders Ekdahl","email":"anders.ekdahl@avensia.com"},"license":"MIT","_id":"@avensia-oss/ts-transform-import-to-lazy-async-import@0.0.3","maintainers":[{"name":"avensia-oss","email":"andekd@avensia.com"}],"homepage":"https://github.com/avensia-oss/ts-transform-import-to-react-lazy","bugs":{"url":"https://github.com/avensia-oss/ts-transform-import-to-react-lazy"},"dist":{"shasum":"93313530a3b1069643305e7c73b14d70def37e60","tarball":"https://registry.npmjs.org/@avensia-oss/ts-transform-import-to-lazy-async-import/-/ts-transform-import-to-lazy-async-import-0.0.3.tgz","fileCount":10,"integrity":"sha512-TGFLUTfMbeAizqfxL3zdF/D5OgVSvm26E5RLkRxr4hX5oJ7G5X5c6ZmMZxhx+ZAoe8+8xflD7sIVpNNE8xDFZA==","signatures":[{"sig":"MEQCIG5dkdZfPVXaI4hHbd0RSqCSrzGCG/RQ0LjDL/k+EJFmAiA+mEjQZqjj5oJO5qoRzEyC/9kYrOXGix02oGO6JoXsmw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":22195,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJct0EFCRA9TVsSAnZWagAAeuoP/02vPJpwSXxDoFoGMp8J\nc227bJ9QuvTKaAeGpbJN0X811s8lL1dwAl3u6oj1xkkBpWlidbk9t1+AOZIu\niun+ghE1uQg9RF9DuDrhAsZQsEhs5Qw6LrZ4a9B8us7Y56l3Ua0ifKUqAp+0\nwa+ogMeIC3mwuY13Jp/fd5RRpa7aXaXsXjT4UuAhotwDSTbiIUa9q232nKPn\nDOvUcQ9VvqRX+6OLu97FrS5FPhWkymsXus6rVMoqNT/8lrARVIn3leuGqwyK\nBaAigLnLn1JMHlhfTsc22Hy9VSYgAMLsHndES3XLpn7bKMBYqjVutxuogCei\nE5+/sBVTTfCCpfKBqkhV1u7H40Mp5bBhms8zM9+E4liRC1A2Mrql7r0PYSBs\npQFcbDJQuDW57b2A69P7KH5w7boGUU00Lg9EpbclZBzVpO6Bhs30XJmsNlgu\nTYH4eMY/32JLPIn4MHcD4n+V2Shygfio83vWfwR6g6qU3EncXcJ9VjSnb9Cy\nnEOlFNvs5GdH49Ik35bJJLmAklTAQCSD+YG0XRjMJ0Bu52oB8ljS+UnvAvND\n54N6I3lpfUh18KolxSm3yaW3PmH2qr3fBl/eAlC6KhJKEOMYvoOqxb22hexZ\nGzzh0rUw1xkpon9gsQkL6ibDz9eHK5Q6N3Unrme66AfPCgmxY9kT1GlCe4SD\ne4iP\r\n=Krb3\r\n-----END PGP SIGNATURE-----\r\n"},"main":"index.js","types":"dist/src/index.d.ts","private":false,"scripts":{"test":"jest","build":"tsc --version && tsc --project \"./\""},"_npmUser":{"name":"avensia-oss","email":"andekd@avensia.com"},"description":"A TypeScript custom transformer that rewrites synchronously loaded React components to async, lazy loaded components","directories":{},"licenseText":"MIT License\n\nCopyright (c) Avensia AB and its affiliates.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.","dependencies":{"@types/react":"^16.7.18"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^23.6.0","ts-jest":"^23.10.5","ts-node":"^7.0.1","prettier":"^1.15.3","typescript":"^3.2.2","@types/jest":"^23.3.10","@types/node":"^10.12.18"},"peerDependencies":{"typescript":"*"},"_npmOperationalInternal":{"tmp":"tmp/ts-transform-import-to-lazy-async-import_0.0.3_1555513605010_0.04610808682052436","host":"s3://npm-registry-packages"}}},"time":{"created":"2019-01-04T13:44:31.881Z","modified":"2026-09-21T11:35:05.348Z","0.0.1":"2019-01-04T13:44:32.234Z","0.0.2":"2019-04-17T14:49:37.698Z","0.0.3":"2019-04-17T15:06:45.112Z"},"bugs":{"url":"https://github.com/avensia-oss/ts-transform-import-to-react-lazy"},"author":{"name":"Anders Ekdahl","email":"anders.ekdahl@avensia.com"},"license":"MIT","homepage":"https://github.com/avensia-oss/ts-transform-import-to-react-lazy","keywords":["TypeScript","transform","transformer","react","import","lazy"],"description":"A TypeScript custom transformer that rewrites synchronously loaded React components to async, lazy loaded components","maintainers":[{"email":"eric.lindell@avensia.com","name":"lindelleric"},{"email":"johan.book@avensia.com","name":"johboo"},{"email":"johan.nilsson@avensia.com","name":"yoohahn-avensia"}],"readme":"# ts-transform-import-to-lazy-async-import\n\n_Note! This transformer is currently experimental_\n\nA TypeScript custom transformer that turns your synchronously imported components into lazy loaded through `React.lazy()` (or a factory of your choosing). You\ncan either pass in a list of components to rewrite (you can use this transform to get the data:\nhttps://github.com/avensia-oss/ts-transform-instrument-react-components) or you can choose to rewrite all components that is found.\n\nThis transformer will essentially rewrite this:\n\n```js\nimport React from 'react';\nimport SomeComponent from './SomeComponent';\n\nexport default (props: any) => <div><SomeComponent /></div>;\n```\n\nTo this:\n\n```js\nimport React from 'react';\nconst SomeComponent = React.lazy(() => import('./SomeComponent'));\n\nexport default (props: any) => <div><SomeComponent /></div>;\n```\n\nNote that it also works with named exports and not just default exports. Meaning it will turn this:\n\n```js\nimport React from 'react';\nimport { SomeComponent } from './SomeComponent';\n\nexport default (props: any) => <div><SomeComponent /></div>;\n```\n\nTo this:\n\n```js\nimport React from 'react';\nconst SomeComponent = React.lazy(() => import('./SomeComponent').then(m => ({default: m.SomeComponent})));\n\nexport default (props: any) => <div><SomeComponent /></div>;\n```\n\nThe React team only wants to support default exports for now and you shouldn't manually write code like this. This transformer will be updated accordingly\nwhen/if React changes how it deals with default/named exports so you don't have to care. Also note that it's possible to turn this off. See below in the options section.\n\n## Other useful transform\n\nIf you don't want to turn all your imports into async imports you can use this transform: https://github.com/avensia-oss/ts-transform-instrument-react-components\nto first get a list of components that aren't rendered on the initial render.\n\n# Installation\n\n```\nyarn add @avensia-oss/ts-transform-import-to-lazy-async-import\n```\n\n## Options\n\n### Other factory than `React.lazy`\n\nIt's possible to specify some other expression than `React.lazy` (since it currently doesn't support server rendering). If you want to use `@loadable` instead you can configure this transform with this options object:\n\n```js\ngetCustomTransformers: (program) => ({\n  before: [importToLazyAsyncImport(program, {\n    createComponentWrapperExpression: ts => {\n      return ts.createIdentifier('loadable');\n    },\n    createImportDeclaration: (ts, currentFile) => {\n      return ts.createImportDeclaration(\n        undefined,\n        undefined,\n        ts.createImportClause(ts.createIdentifier('loadable'), undefined),\n        ts.createStringLiteral('@loadable/component'),\n      );\n    },\n  })]\n})\n```\n\n### Only rewriting default exports\n\nIf you want to stick to the rules you can tell this transformer to only rewrite an import if it's a default import.\n\n```js\ngetCustomTransformers: (program) => ({\n  before: [importToLazyAsyncImport(program, {\n    onlyRewriteDefaultExports: true,\n  })]\n})\n```\n\n### Only rewriting if the import statement can be removed\n\nBy default this transform will rewrite all component imports, even if the same import statement imports other things as well. This might not be what you want,\nsince in that case the original import statement won't be fully removed and the value of lazy loading the components is very small. The reason for this default\nbehavior is that this transform can't know if some other tool (such as https://github.com/avensia-oss/ts-transform-export-const-folding) is able to remove the\nother imports.\n\n```js\ngetCustomTransformers: (program) => ({\n  before: [importToLazyAsyncImport(program, {\n    onlyRewriteIfImportCanBeRemoved: true,\n  })]\n})\n```\n\n### Dynamically determining when to rewrite\n\nIf you have a list of files you want to lazy load (like the result of https://github.com/avensia-oss/ts-transform-instrument-react-components) you can implement\nit like this:\n\n```js\nimport * as path from 'path';\n\ngetCustomTransformers: (program) => ({\n  before: [importToLazyAsyncImport(program, {\n    shouldRewrite: (importSpecifier: string, currentFile: string) => {\n      const fullPath = path.join(currentFile, importSpecifier);\n      return myListOfFilesToAsyncLoad.indexOf(fullPath) !== -1;\n    }\n  })]\n})\n```\n\n## Usage with webpack\n\nUnfortunately TypeScript doesn't let you specifiy custom transformers in `tsconfig.json`. If you're using `ts-loader` with webpack you can specify it like this:\nhttps://github.com/TypeStrong/ts-loader#getcustomtransformers-----before-transformerfactory-after-transformerfactory--\n\nThe default export of this module is a function which expects a `ts.Program` an returns a transformer function. Your config should look something like this:\n\n```js\nconst importToLazyAsyncImport = require('@avensia-oss/ts-transform-import-to-lazy-async-import');\n\nreturn {\n  ...\n  options: {\n    getCustomTransformers: (program) => ({\n      before: [importToLazyAsyncImport(program, options)] // See options above\n    })\n  }\n  ...\n};\n```\n","readmeFilename":"README.md"}