{"name":"esbuild-plugin-alias","version":"0.1.1","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":"5d91d1d5670ef5c8e8cd0e44436bb9ddf075c621","_id":"esbuild-plugin-alias@0.1.1","_nodeVersion":"12.16.3","_npmVersion":"6.14.4","dist":{"integrity":"sha512-18xfnynzxXPJ+q99AR6gQdLXDHmHNscSWNkZngjAqegl32U/2y24/MwEbb1FSaAbLBKn5LgYGaaJdEkbBnif5w==","shasum":"3d41d977ceafacbfb70f3b46fe12de30ceef7207","tarball":"http://registry-npm.ywwl.com/esbuild-plugin-alias/download/esbuild-plugin-alias-0.1.1.tgz","fileCount":5,"unpackedSize":4448,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgJlu0CRA9TVsSAnZWagAAR5oP/iLJwJle1tTay6zvM4Wz\nERhHixoMee+UEUXjTdy56Vwb38fyY5gRzwMAPNeaTD0NzoTY+4WmyNPB9DNQ\n2haYGZpyZ3pWXAW3qdMLyzfAIOP3Zo19I0fdeXno8hIIG46ttBeLjHQtH+jE\nT8Ue2TMkf8IDjUyI892WlotPIeoA3c/wHPG2UXGbXSH0btbFMhCqxPTwSgbu\nL65fArkR6V8ARla/iEJEPzPClkKh2AiY5bao0TM1Czf7b6/46cGKRn8A3aI8\nSikDyAEk5JOkTs6CulKjNybhqK5acMuI62lKpGNdYXE/VCF7cp8m50O7R/d+\nh9mdkLKPMtEP+DBGOs7drOFN856Lk+HmkV3zF9qVhGPs2BJf8LcOWlWhbPBi\ncbjkcxjhWQN/oQuWbWzq3ApvARPKE/bBV7HzhT0/CzMt3gloKlHxfF+WzNxM\n8SOs/xMg8f+lluZtWi6N4cstsJoB4/5EtplyhXVE70m4dmz8RAwazZ45VH+v\nOer4rS3vUy47br4QZw/a2wf8KFh8nFJakdV7j83RATMLSzQVSzq0Bw6kOcd7\n7uVz9i273B8Mlm29/e4bXR64aX8KNkxzUTrP+uEW7+gIeam9rB5F7vlJNzMM\nQy8Sq29RdtdW37hnQ9yh+GAMcLW1oiWJuYQy7bIS4WMuDK99cFA8AyhOQuHp\nOHaR\r\n=XhMv\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBqFAgPalqTF4m6FX3Rj3qLxyiwJpDEg+1wI1GLKq8YTAiALnkQef8xPK38bUCTSnK4OGAwgK+HDVhDbtfZhiHPHnQ=="}],"size":2387,"noattachment":false,"key":"/esbuild-plugin-alias/-/esbuild-plugin-alias-0.1.1.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.1_1613126579507_0.014596138872027709"},"_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":1613126579652,"_cnpm_publish_time":1613126579652,"dist-tags":{"latest":"0.2.1"}}