Installations
npm install babel-plugin-import-glob
Developer Guide
Typescript
No
Module System
N/A
Min. Node Version
>=4
Node Version
7.8.0
NPM Version
4.6.1
Score
77.8
Supply Chain
98.9
Quality
75.5
Maintenance
100
Vulnerability
98.6
License
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
novemberborn
Download Statistics
Total Downloads
1,755,286
Last Day
771
Last Week
4,540
Last Month
21,791
Last Year
216,908
GitHub Statistics
59 Stars
55 Commits
15 Forks
3 Watching
1 Branches
3 Contributors
Bundle Size
73.42 kB
Minified
22.03 kB
Minified + Gzipped
Package Meta Information
Latest Version
2.0.0
Package Id
babel-plugin-import-glob@2.0.0
Size
4.27 kB
NPM Version
4.6.1
Node Version
7.8.0
Publised On
20 May 2017
Total Downloads
Cumulative downloads
Total Downloads
1,755,286
Last day
-38.5%
771
Compared to previous day
Last week
-33.3%
4,540
Compared to previous week
Last month
37.5%
21,791
Compared to previous month
Last year
-30.5%
216,908
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
3
Dev Dependencies
5
babel-plugin-import-glob
Babel plugin to enable importing modules using a glob pattern. Tested with Node.js 4 and above.
Installation
npm install --save-dev babel-plugin-import-glob
Then add import-glob
to your .babelrc
file, like:
1{ 2 "plugins": ["import-glob"] 3}
Usage
This plugin is useful if you have multiple modules but you don't want to import them one at a time.
Maybe you're using the
handlebars-inline-precompile
plugin and are putting your modules in a templates
directory. Or you need to
dynamically reference one out of several classes and don't want to maintain the
lookup by hand. Perhaps you need to load multiple modules for their side-effects
and wish to simply add them to a directory without additional work. If so, this
plugin is for you!
Of course in the vast majority of cases you should just use normal import statements. Don't go overboard using this plugin.
You can import the default members of any matching module. Let's say you have a directory layout like this:
index.js
templates/main.handlebars.js
templates/_partial.handlebars.js
In index.js
you can write:
1import { main, _partial } from './templates/**/*.handlebars.js'
You can add an optional glob:
prefix:
1import { main, _partial } from 'glob:./templates/**/*.handlebars.js'
You can alias members:
1import { main, _partial as partial } from './templates/**/*.handlebars.js'
Or import all matches into a namespace object:
1import * as templates from './templates/**/*.handlebars.js' 2// Provides `templates.main` and `templates._partial`
Note that you cannot import the default from the glob pattern. The following
won't work and throws a SyntaxError
:
1import myTemplates from './templates/**/*.handlebars.js' // This will throw a SyntaxError
You can load modules for their side-effects though:
1import './modules-with-side-effects/*.js'
Glob patterns
The plugin uses the glob
package. Please refer to its documentation regarding
the pattern syntax.
The glob pattern must be relative. It must start with ./
or ../
. A
SyntaxError
is thrown otherwise.
Import members
Identifiers are generated for all matches using the dynamic portions of the pattern. File-separators in the resulting strings are replaced by dollar signs. The strings are then converted into identifiers.
A valid identifier cannot always be generated. If that's the case a
SyntaxError
is thrown with more details. Similarly multiple matches may result
in the same identifier. This also results in a SyntaxError
being thrown.
For the ./templates/**/*.handlebars.js
example above the matches are:
./templates/main.handlebars.js
./templates/_partial.handlebars.js
The dynamic portions are main
and _partial
. These are valid identifiers and
therefore used as the import members.
A SyntaxError
is throw when importing a member that does not correspond to a
match:
1import { doesNotExist } from './templates/**/*.handlebars.js' // This will throw a SyntaxError
Here's an overview of how the members are determined for additional matches:
Match | Result | Reason |
---|---|---|
./templates/terms-and-conditions.handlebars.js | termsAndConditions | The - cannot be used in the identifier so it's removed. The following character is uppercased |
./templates/blog/footer.handlebars.js | blog$footer | The blog directory is captured by the ** expression in the pattern. It is joined with the footer name using a dollar sign |
./templates/-main.handlebars.js | SyntaxError | The - is removed, resulting in the same identifier as for main.handlebars.js |
./templates/new.handlebars.js | _new | new is a reserved word so it's prefixed with an underscore |
./templates/blog/new.handlebars.js | blog$new | Even though new is a reserved word, it's combined with blog$ so no prefix is necessary |
./templates/404.handlebars.js | _404 | Identifiers can't start with digits so it's prefixed with an underscore |
./templates/error-pages/404.handlebars.js | errorPages$404 | Now that 404 is combined with errorPages$ it no longer needs to be prefixed |
./templates/????.handlebars.js | SyntaxError | No identifier can be generated for ???? |
Brace expansions are not considered to be a dynamic portion of the pattern.
Given the pattern ./templates/{blog,error-pages}/*.handlebars.js
:
Match | Result |
---|---|
./templates/blog/footer.handlebars.js | footer |
./templates/error-pages/404.handlebars.js | _404 |
Use parentheses patterns instead, e.g.
./templates/{@(blog),@(error-pages)}/*.handlebars.js
:
Match | Result |
---|---|
./templates/blog/footer.handlebars.js | blog$footer |
./templates/error-pages/404.handlebars.js | errorPages$404 |
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: ISC License: LICENSE:0
Reason
Found 6/23 approved changesets -- score normalized to 2
Reason
project is archived
Details
- Warn: Repository is archived.
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 17 are checked with a SAST tool
Score
3.3
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to babel-plugin-import-glob
babel-plugin-transform-vite-meta-glob
babel plugin that emulates vite's import.meta.glob import.meta.globEager functionality
babel-plugin-glob-import
Babel plugin to use glob patterns in import and require statements.
babel-plugin-import-glob-fix
Babel plugin to enable importing modules using a glob pattern
babel-plugin-import-glob-array
Transform a directory import to individual imports represented as an array