andreyvital / Babel Plugin Global Require
A simple plugin that allows you to require globally
Stars: ✭ 102
Programming Languages
javascript
184084 projects - #8 most used programming language
Labels
Projects that are alternatives of or similar to Babel Plugin Global Require
npm-es-modules
Breakdown of 7 different ways to use ES modules with npm today.
Stars: ✭ 67 (-34.31%)
Mutual labels: commonjs
Vue Drawer Layout
A simple DrawerLayout component for Vue.js.
Stars: ✭ 392 (+284.31%)
Mutual labels: commonjs
Units Converter
A simple utility library to measure and convert between units
Stars: ✭ 31 (-69.61%)
Mutual labels: commonjs
WSHModule
WSHModule is a JavaScript virtual machine built in WSH/JScript.
Stars: ✭ 28 (-72.55%)
Mutual labels: commonjs
Node Dependency Tree
Get the dependency tree of a module
Stars: ✭ 383 (+275.49%)
Mutual labels: commonjs
Esbuild
An extremely fast JavaScript and CSS bundler and minifier
Stars: ✭ 29,374 (+28698.04%)
Mutual labels: commonjs
array-sort-by
Powerful mechanism to sort arrays or array of objects by one or more properties. You can also specify a custom comparer function.
Stars: ✭ 37 (-63.73%)
Mutual labels: commonjs
Detective
Find all calls to require() no matter how deeply nested using a proper walk of the AST
Stars: ✭ 387 (+279.41%)
Mutual labels: commonjs
Webpack Common Shake
CommonJS Tree Shaker plugin for WebPack
Stars: ✭ 875 (+757.84%)
Mutual labels: commonjs
mock-spy-module-import
JavaScript import/require module testing do's and don'ts with Jest
Stars: ✭ 40 (-60.78%)
Mutual labels: commonjs
blingblingjs
💲 Micro-library of shorthands for DOM selection, events, and attribute manipulation
Stars: ✭ 164 (+60.78%)
Mutual labels: commonjs
Browserify Rails
Browserify + Rails = a great way to modularize your legacy JavaScript
Stars: ✭ 701 (+587.25%)
Mutual labels: commonjs
mpx-es-check
Checks the version of ES in JavaScript files with simple shell commands
Stars: ✭ 15 (-85.29%)
Mutual labels: commonjs
Neuron.js
A Full Feature CommonJS Module Manager, Dependency Graph Handler and Loader for Browsers
Stars: ✭ 66 (-35.29%)
Mutual labels: commonjs
timezz
With this plugin, you can easily make a stopwatch or timer on your site. Just init, style and enjoy.
Stars: ✭ 35 (-65.69%)
Mutual labels: commonjs
Madge
Create graphs from your CommonJS, AMD or ES6 module dependencies
Stars: ✭ 5,635 (+5424.51%)
Mutual labels: commonjs
Common Shakeify
browserify tree shaking plugin using `common-shake`
Stars: ✭ 101 (-0.98%)
Mutual labels: commonjs
Typescript Restful Starter
Node.js + ExpressJS + Joi + Typeorm + Typescript + JWT + ES2015 + Clustering + Tslint + Mocha + Chai
Stars: ✭ 97 (-4.9%)
Mutual labels: commonjs
Bonsai
Understand the tree of dependencies inside your webpack bundles, and trim away the excess.
Stars: ✭ 732 (+617.65%)
Mutual labels: commonjs
babel-plugin-global-require
Installation
npm install --save-dev babel-plugin-global-require
Tell the plugin where's your root (.babelrc):
{
"plugins": [
["global-require", {
"root": "src"
}]
]
}
What are the benefits?
- You'll use the same require statement from anywhere in your project;
- You'll avoid path hell
../../../../..
; - You'll write a more concise code.
This plugin is convention based: the alias is always the name of the file. For example:
src (root)
util
queue
InMemoryAcknowledgingQueue.js
PriorityQueue.js
CallbackQueue.js
...
io
NuclearEventEmitter.js
user
UserActions.js
UserStore.js
security
authorization
rbac
Role.js
...
Then:
import NuclearEventEmitter from 'NuclearEventEmitter'
// (...)
import UserStore from 'UserStore'
// require
var Role = require('Role')
It will translate 'NuclearEventEmitter'
to src/io/NuclearEventEmitter.js
for you. And the same happens to UserStore
and Role
.
index.js
by parent folder name is supported!
Requiring It is common to require an index.js
file by the name of its parent directory, for example:
src
security
authorisation
index.js
Instead of:
require('./security/authorisation')
You'll write:
require('authorisation')
But what about conflicts?
Given the following structure:
src
security
authorization
rbac
hasAccessTo.js
acl
hasAccessTo.js
You can't require hasAccessTo.js
only by its name because it would result in a require of undesired file. So for this specific case, the conflict is resolved simply by going up one directory (and it keeps going until there's no conflict):
import { hasAccessTo as ... } from 'rbac/hasAccessTo'
import { hasAccessTo as ... } from 'acl/hasAccessTo'
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].