{"name":"esbuild-plugin-alias","version":"0.1.2","description":"esbuild plugin for path aliases","main":"index.js","scripts":{"test":"mocha","lint":"eslint ."},"repository":{"type":"git","url":"git+https://github.com/igoradamenko/esbuild-plugin-alias.git"},"keywords":["esbuild","alias","plugin"],"author":{"name":"Igor Adamenko","email":"mail@igoradamenko.com","url":"https://igoradamenko.com"},"license":"MIT","bugs":{"url":"https://github.com/igoradamenko/esbuild-plugin-alias/issues"},"homepage":"https://github.com/igoradamenko/esbuild-plugin-alias#readme","devDependencies":{"@funboxteam/eslint-config":"5.3.0","esbuild":"0.8.44","eslint":"7.19.0","husky":"4.3.8","lint-staged":"10.5.4","mocha":"8.2.1"},"husky":{"hooks":{"pre-commit":"lint-staged -q"}},"lint-staged":{"*.js":"eslint --fix"},"gitHead":"089dd80af5cb6f5fd0ce6e2d52f68a58c1f82fde","_id":"esbuild-plugin-alias@0.1.2","_nodeVersion":"12.16.3","_npmVersion":"6.14.4","dist":{"integrity":"sha512-WsX0OJy8IGOsGZV+4oHEU5B6XQUpxOsZN1iSoYf9COTDbY7WXcOwd1oCLYNWUIWCExyGXSghIGq2k7sXBldxwQ==","shasum":"1232fbde807c0c8ad44c44ec859819eb492e12a8","tarball":"http://registry-npm.ywwl.com/esbuild-plugin-alias/download/esbuild-plugin-alias-0.1.2.tgz","fileCount":5,"unpackedSize":4661,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgJnNICRA9TVsSAnZWagAAckAP/3tcFYXrtXjTFCv+/HMq\nzcungYJrEIBh0qzH1+/os807ZGJhkZPrpMtlHVSMMAS7Ja5FBfcn6mkpRtcv\n1SoBhUEqMuso9/Ci/cMd+T570kGIprhwPwHneYPXLo36rZCKv+DpnpnBGXKy\nUgzutOKw/yqi76BqQQXmNg/Ufco0Mrkv6BDWQR628rxyz4tH+K0MW0fUM0qB\n2VOwDoMqhng73aYL9zict2hkBvPLVDDOcz6z4DyWE/lXjC+u/VqFFL881XXy\nRAJbIBDq+qv7/6v2kCteRp9bOs8kyNTgXJSFltNTC8DQSnjZrNE/QZTYvefQ\nUIUk4YMLAgeAAgR+ILGVr6nZb6rcMIgKJmGST8wGV88GgLVHoTze9ShguIdS\nWvAY+OXFc2FxjeJiIQxGGpHZDnQLTBOl1EBvZoyQIq3EWya9/RBgNZFXaIno\n2UJCXdN/6APzxe9F1B7OfwOBDe+cqKGCHDryVs43ymPaCaYlzJCzHr4yZ53Z\n1Rf3UvAgi6oMKa3OzcZQzpOrVw7IEYxW5mWagrNbULHnJacYGaaJoYsNhUWp\nJ35pRO5WHX5yqnF0MfpSK8A0J7yBV3X541LWPX3UEpDW6a2cONr7bzJ31QUa\nEPNh118nHizcgkdXJD9gpzST25gjQglQJqSwxujZWVZybYhO7IzSVe7Gk2t1\nL7xn\r\n=rix3\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCIZhVhfAGGDJlkHeTdh9wrSda2Iw9W6fqQhHIHVYOkLQIhAMCGbaWuy1+efAGawRbkuiyhKu1wl4gz130KzFqgmRa4"}],"size":2487,"noattachment":false,"key":"/esbuild-plugin-alias/-/esbuild-plugin-alias-0.1.2.tgz"},"_npmUser":{"name":"igoradamenko","email":"mail@igoradamenko.com"},"directories":{},"maintainers":[{"name":"igoradamenko","email":"mail@igoradamenko.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/esbuild-plugin-alias_0.1.2_1613132615892_0.11542830110725233"},"_hasShrinkwrap":false,"readme":"# esbuild-plugin-alias\n\n[![npm](https://img.shields.io/npm/v/esbuild-plugin-alias.svg)](https://www.npmjs.com/package/esbuild-plugin-alias)\n\n[esbuild](https://github.com/evanw/esbuild) plugin for path aliases.\n\n\n## Rationale\n\nSometimes it's useful to have dynamic imports that resolves into different files depending on some conditions \n(e.g. env variables).\n\n\n## Installation\n\n```sh\nnpm install --save-dev esbuild-plugin-alias\n```\n\n\n## Usage\n\nDefine plugin in the `plugins` section of esbuild config like this:\n\n```js\nconst esbuild = require('esbuild');\nconst alias = require('esbuild-plugin-alias');\n\nesbuild.build({\n  // ...\n  plugins: [\n    alias({\n      'imported-path': '/home/user/lib/src/resolved-path',\n    }),\n  ],\n})\n```\n\n**Note:** esbuild requires resolved paths to be absolute. So, make sure that values in plugin's config object are\nabsolute paths.\n\nIf you need to find a path to an installed dep, you may use `require.resolve`. E.g.:\n\n```js\nalias({\n  'react-dom': process.env.NODE_ENV === 'dev' \n    ? require.resolve('@hot-loader/react-dom')\n    : require.resolve('react-dom'),\n}),\n```\n\n\n## Example\n\nHaving this input file:\n\n```js\n// src/app.js\nimport settings from 'settings.env';\n\nconsole.log(settings);\n```\n\nAnd esbuild config like this:\n\n```js\n// config/build.js\nconst path = require('path');\nconst esbuild = require('esbuild');\nconst alias = require('esbuild-plugin-alias');\n\nesbuild.build({\n  entryPoints: ['in.js'],\n  bundle: true,\n  outfile: 'out.js',\n  plugins: [\n    alias({\n      'settings.env': path.resolve(__dirname, `../src/settings.${process.env.NODE_ENV}.js`),\n    }),\n  ],\n}).catch(err => process.exit(1));\n```\n\nYou will get `src/settings.dev.js` loaded instead of `settings.env` when `NODE_ENV` equals `dev`.\n\nCheck [test/](test) for more detailed example.\n","publish_time":1613132616059,"_cnpm_publish_time":1613132616059,"dist-tags":{"latest":"0.2.1"}}