{"id":14155890,"url":"https://github.com/benbria/aliasify","last_synced_at":"2025-04-05T00:07:35.537Z","repository":{"id":12650365,"uuid":"15322001","full_name":"benbria/aliasify","owner":"benbria","description":"Rewrite require calls in browserify modules.","archived":false,"fork":false,"pushed_at":"2016-12-01T22:50:53.000Z","size":83,"stargazers_count":203,"open_issues_count":11,"forks_count":26,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-02-01T20:07:42.112Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"CoffeeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/benbria.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-12-19T20:28:23.000Z","updated_at":"2024-11-25T05:47:37.000Z","dependencies_parsed_at":"2022-09-26T18:41:13.000Z","dependency_job_id":null,"html_url":"https://github.com/benbria/aliasify","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benbria%2Faliasify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benbria%2Faliasify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benbria%2Faliasify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benbria%2Faliasify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/benbria","download_url":"https://codeload.github.com/benbria/aliasify/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237839055,"owners_count":19374308,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-17T08:05:04.365Z","updated_at":"2025-02-08T21:09:55.607Z","avatar_url":"https://github.com/benbria.png","language":"CoffeeScript","readme":"[![Build Status](https://travis-ci.org/benbria/aliasify.svg)](https://travis-ci.org/benbria/aliasify)\n[![Coverage Status](https://coveralls.io/repos/benbria/aliasify/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/benbria/aliasify?branch=master)\n\nAliasify is a [transform](https://github.com/substack/node-browserify#btransformtr) for [browserify](https://github.com/substack/node-browserify) which lets you rewrite calls to `require`.\n\nInstallation\n============\n\nInstall with `npm install --save-dev aliasify`.\n\nUsage\n=====\n\nTo use, add a section to your package.json:\n\n    {\n        \"aliasify\": {\n            \"aliases\": {\n                \"d3\": \"./shims/d3.js\",\n                \"underscore\": \"lodash\"\n            }\n        }\n    }\n\nNow if you have a file in src/browserify/index.js which looks like:\n\n    d3 = require('d3')\n    _ = require('underscore')\n    ...\n\nThis will automatically be transformed to:\n\n    d3 = require('../../shims/d3.js')\n    _ = require('lodash')\n    ...\n\nAny replacement that starts with a \".\" will be resolved as a relative path (as \"d3\" above.)  Replacements that start with any other character will be replaced verbatim (as with \"underscore\" above.)\n\nConfiguration\n=============\n\nConfiguration can be loaded in multiple ways;  You can put your configuration directly in package.json, as in the example above, or you can use an external json or js file.  In your package.json:\n\n    {\n        \"aliasify\": \"./aliasifyConfig.js\"\n    }\n\nThen in aliasifyConfig.js:\n\n    module.exports = {\n        aliases: {\n            \"d3\": \"./shims/d3.js\"\n        },\n        verbose: false\n    };\n\nNote that using a js file means you can change your configuration based on environment variables.\n\nAlternatively, if you're using the Browserify API, you can configure your aliasify programatically:\n\n    aliasifyConfig = {\n        aliases: {\n            \"d3\": \"./shims/d3.js\"\n        },\n        verbose: false\n    }\n\n    var b = browserify();\n    b.transform(aliasify, aliasifyConfig);\n\nnote that using the browserify API, './shims/d3.js' will be resolved against the current working\ndirectory.\n\nConfiguration options:\n* `aliases` - An object mapping aliases to their replacements.\n* `replacements` - An object mapping RegExp strings with RegExp replacements, or a function that will return a replacement.\n* `verbose` - If true, then aliasify will print modifications it is making to stdout.\n* `configDir` - An absolute path to resolve relative paths against.  If you're using package.json, this will automatically be filled in for you with the directory containing package.json.  If you're using a .js file for configuration, set this to `__dirname`.\n* `appliesTo` - Controls which files will be transformed.  By default, only JS type files will be transformed ('.js', '.coffee', etc...).  See [browserify-transform-tools documentation](https://github.com/benbria/browserify-transform-tools/wiki/Transform-Configuration#common-configuration) for details.\n\nRelative Requires\n=================\n\nWhen you specify:\n\n    aliases: {\n        \"d3\": \"./shims/d3.js\"\n    }\n\nThe \"./\" means this will be resolved relative to the current working directory (or relative to the\nconfiguration file which contains the line, in the case where configuration is loaded from\npackage.json.)  Sometimes it is desirable to literally replace an alias; to resolve the alias\nrelative to the file which is doing the `require` call.  In this case you can do:\n\n    aliases: {\n        \"d3\": {\"relative\": \"./shims/d3.js\"}\n    }\n\nThis will cause all occurences of `require(\"d3\")` to be replaced with `require(\"./shims/d3.js\")`,\nregardless of where those files are in the directory tree.\n\nRegular Expression Aliasing\n===========================\nYou can use the `replacements` configuration section to create more powerful aliasing.  This is useful if you\nhave a large project but don't want to manually add an alias for every single file.  It is also incredibly useful when you want to combine\naliasify with other transforms, such as hbsfy, reactify, or coffeeify.\n\n    replacements: {\n        \"_components/(\\\\w+)\": \"src/react/components/$1/index.jsx\"\n    }\n\nWill let you replace `require('_components/SomeCoolReactComponent')` with `require('src/react/components/SomeCoolReactComponent/index.jsx')`\n\nYou can also match an alias and pass a function which can return a new file name.\n\n`require(\"_coffee/delicious-coffee\");`\n\nUsing this configuration:\n\n    replacements: {\n        \"_coffee/(\\\\w+)\": function (alias, regexMatch, regexObject) {\n            console.log(alias); // _coffee/delicious-coffee\n            console.log(regexMatch); // _coffee/(\\\\w+)\n            return 'coffee.js'; // default behavior - won't replace\n        }\n    }\n\n\nStubbing Out Packages\n=====================\n\nYou can remove a package entirely for browser builds using:\n\n    aliases: {\n        \"d3\": false\n    }\n\nNow any code which tries to `require('d3')` will end up compiling to:\n\n    var d3 = {};\n\n\nSupport aliasing requireish function calls\n=====================\n\nYou can tell aliasify to also replace aliases in other functions than `require`. This can become very helpful if you are planing on wrap\nnode's require function with another one. For example in case of [proxyquireify](https://github.com/thlorenz/proxyquireify) this is very helpful.\n\n```JavaScript\n    var aliasify = require(\"aliasify\").requireish([\"require\", \"foo\", \"bar\"])\n```\n\nwith this options:\n\n    aliases: {\n            \"d3\": {\"relative\": \"./shims/d3.js\"}\n        }\n\nNow any code which tries to `require('d3')` or `foo('d3')` or even `bar('d3')` will end up compiling to:\n\n`require(\"./shims/d3.js\")` respectively `foo(\"./shims/d3.js\")` respectively `bar(\"./shims/d3.js\")`\n\nThe argument for `requireish()` can be either a string or an array of strings.\n\nA few things to note: first, if you specify `requireish`, you must explicitly list `require` in the list of requireish\nthings to transform, or it won't be.\n\nSecond, note that aliasify only replaces the first string parameter of the \"requireish\" function call. All other\narguments are preserved as they were passed in. (e.g. `require('d3', 'foo')` turns into\n`require('./shims/d3.js', 'foo')`.)  Caution! Do NOT pass in arguments that have circular references. If you need that,\nthan just pass in an identifier for the object having circular references!\n\nAlternatives\n============\n\n`aliasify` is essentially a fancy version of the [`browser` field](https://gist.github.com/defunctzombie/4339901#replace-specific-files---advanced) from package.json, which is [interpreted](https://github.com/substack/node-browserify#packagejson) by browserify.\n\nUsing the `browser` field is probably going to be faster, as it doesn't involve running a transform on each of your files.  On the other hand, `aliasify` gives you a finer degree of control and can be run before other transforms (for example, you can run `aliasify` before [debowerify](https://github.com/eugeneware/debowerify), which will let you replace certain components that debowerify would otherwise replace.)\n","funding_links":[],"categories":["others","Tools"],"sub_categories":["Transforms"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenbria%2Faliasify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenbria%2Faliasify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenbria%2Faliasify/lists"}