Gathering detailed insights and metrics for glob-import-loader
Gathering detailed insights and metrics for glob-import-loader
Gathering detailed insights and metrics for glob-import-loader
Gathering detailed insights and metrics for glob-import-loader
import-glob-loader
Globbing preloader for Webpack
webpack-import-glob-loader
ES6 import with glob patterns (preloader for Webpack)
@arbz/glob-import-loader
A Webpack loader that enables glob imports, allowing you to dynamically import multiple files matching a glob pattern with their relative paths.
destructured-import-glob-loader
Destructured JS globbing loader for Webpack
npm install glob-import-loader
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
6 Stars
51 Commits
3 Forks
1 Watchers
2 Branches
1 Contributors
Updated on Mar 27, 2024
Latest Version
1.2.0
Package Id
glob-import-loader@1.2.0
Unpacked Size
22.64 kB
Size
5.51 kB
File Count
15
NPM Version
7.21.1
Node Version
16.9.1
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
4
Webpack loader that enables ES6 imports with glob patterns. Leverages Webpack's Enhanced Resolver to resolve aliases.
Inspired by webpack-import-glob-loader
?
, +
, and !
globbing characters have issues as they're currently incompatible with Enhanced Loader. Looking for workarounds!@use
and @forward
@use
's configuration syntax (with
) and @forward
's configuration syntax (hide
) is not supported and will be ignored. These should not be added in a wildcard fashion and should instead be set individually on each module.
1import modules from "./foo/**/*.js";
Expands into
1import * as module0 from "./foo/1.js"; 2import * as module1 from "./foo/bar/2.js"; 3import * as module2 from "./foo/bar/3.js"; 4 5var modules = [module0, module1, module2];
For importing from node module
1import modules from "a-node-module/**/*js";
Expands into
1import * as module0 from "a-node-module/foo/1.js"; 2import * as module1 from "a-node-module/foo/bar/2.js"; 3import * as module2 from "a-node-module/foo/bar/3.js"; 4 5var modules = [module0, module1, module2];
For side effects:
1import "./foo/**/*.scss";
Expands into
1import "./foo/1.scss"; 2import "./foo/bar/2.scss";
For sass:
1@import "./foo/**/*.scss";
Expands into
1@import "./foo/1.scss"; 2@import "./foo/bar/2.scss";
1@use "./foo/**/*.scss" as *;
Expands into
1@use "./foo/1.scss" as *; 2@use "./foo/bar/2.scss" as *;
1@forward "./foo/**/*.scss" as C;
Expands into
1@forward "./foo/1.scss" as C0; 2@forward "./foo/bar/2.scss" as C1;
1npm install glob-import-loader --save-dev
You can use it one of two ways, the recommended way is to use it as a preloader
1// ./webpack.config.js 2 3module.exports = { 4 ... 5 module: { 6 rules: [ 7 { 8 test: /\.js$/, 9 use: 'glob-import-loader' 10 }, 11 { 12 test: /\.scss$/, 13 use: 'glob-import-loader' 14 }, 15 ] 16 } 17};
Alternatively you can use it as a chained loader
1// foo/bar.js 2import "./**/*.js"; 3 4// index.js 5import "glob-import-loader!foo/bar.js";
Name | Type | Default | Description |
---|---|---|---|
resolve | {Object} | {} | Your Webpack resolution (resolve ) rules. |
banner | {Function} | undefined | An optional function for how wildcard variables should display. Useful for things such as HMR Where names must be predictable. |
ignoreNodeModules | {Boolean} | true * | Determines whether files under node_modules should be ignored. By default, they are ignored unless "node_modules" is present in the glob string. |
resolve
Type: Object
Default: {}
(or default webpack resolution rules)
This object should reference your resolution object in your webpack.config.js configuration.
Example:
webpack.config.js
1const resolve = { 2 alias: { 3 Sprite: path.resolve(__dirname, "src/assets/sprite"), 4 CSS: path.resolve(__dirname, "src/css"), 5 JS: path.resolve(__dirname, "src/js"), 6 }, 7 modules: [path.resolve(__dirname, "node_modules")], 8 extensions: [".js", ".jsx", ".ts", ".tsx", ".json"], 9 plugins: [new DirectoryNamedWebpackPlugin(true)], 10}; 11 12module.exports = { 13 target: 'web', 14 resolve, 15 entry: { ... } 16 module: { 17 rules: [ 18 { 19 test: /\.(j|t)sx?$/, 20 include: [path.resolve(__dirname, 'src')], 21 use: [ 22 'babel-loader', 23 { 24 loader: 'glob-import-loader', 25 options: { 26 resolve, 27 }, 28 }, 29 ], 30 }, 31 ], 32 }, 33 ... other settings ... 34};
banner
Type: Function
Default: undefined
This function gives you granular control over how "import" variables are output in the code should you need it. Can be useful when needing predictable variable names, such as with HMR. The banner
function should return serialized JavaScript. The banner function receives two arguments:
paths
- An array of objects with the following structure:
Name | Description |
---|---|
path | The path to the imported file. |
module | Variable reference to the value exported by the file. |
importString | The import string use by Webpack to import the file |
varname
- The variable name used when importing.
banner
Example:webpack.config.js
1module.exports = { 2 module: { 3 rules: [ 4 { 5 test: /\.(j|t)sx?$/, 6 include: [path.resolve(__dirname, "src")], 7 use: [ 8 "babel-loader", 9 { 10 loader: "glob-import-loader", 11 options: { 12 banner(paths, varname) { 13 if (varname) { 14 return `var ${varname} = {${paths 15 .map( 16 ({ path: fn, module }) => ` 17 "${path.basename(fn).split(".")[0]}":${module} 18 ` 19 ) 20 .join(",")}};`; 21 } 22 }, 23 }, 24 }, 25 ], 26 }, 27 ], 28 }, 29};
entry.js (source)
1import cmpts from "JS/**/*.cmpt.jsx";
entry.js (output)
... webpack import statements ...
// output via `banner` function
var cmpts = {
"loader": _webpack_path_to_module__,
"autocomplete": _webpack_path_to_module__,
"searchresults": _webpack_path_to_module__,
"searchsuggestions": _webpack_path_to_module__
};
ignoreNodeModules
Type: Boolean
Default: true
unless "node_modules" is used within the import string, then false
. Can be set manually to either true or false in which case that value is respected.
ignoreNodeModules
Example:entry.js (source)
1import cmpts from "../**/*.js"; // node_modules are not included by default
entry2.js (source)
1import cmpts from "../node_modules/**/*.js"; // node_modules are included by default
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/27 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
13 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-30
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 More