Repository: gaearon/promise-loader
Branch: master
Commit: 7e6e311e3923
Files: 4
Total size: 3.5 KB
Directory structure:
gitextract_k4fh87rh/
├── .gitignore
├── README.md
├── index.js
└── package.json
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
node_modules
.DS_Store
================================================
FILE: README.md
================================================
## A sister of [bundle-loader](https://github.com/webpack/bundle-loader) with promise API
### Usage
[Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html)
This is a ripoff of [bundle-loader](https://github.com/webpack/bundle-loader) that uses promises instead of callbacks.
It only implements so-called `lazy` `bundle-loader` mode—that is, `require` returns a function that, when invoked, returns a promise that resolves to the module.
`require: (string) -> () -> Promise<module>`
It's up to you to specify your Promise library of choice as a parameter.
``` javascript
// Assuming you use Bluebird
var load = require("promise?bluebird!./file.js");
// The chunk is not requested until you call the load function
load().then(function(file) {
});
```
If a promise library is already loaded externally you can specify 'global'.
You can optionally specify [a name for your chunk](http://webpack.github.io/docs/code-splitting.html#named-chunks) after a comma:
```javascript
var load = require("promise?bluebird,editor!./editor.js");
```
This can be useful for [single-page apps](http://webpack.github.io/docs/optimization.html#single-page-app) because you can later extract filenames from [Webpack-generated stats](https://github.com/webpack/docs/wiki/node.js-api#stats) and pre-load specific bundles if you know user's going to hit them.
The bundle name may include `[filename]`, which will be replaced with the filename, and `[name]`, which omits the extension. This is useful for when you want to configure loaders in Webpack configuration without specifying precise filenames—for example, by a suffix:
```javascript
{
test: /\.i18n\.json$/,
loader: 'promise?global,[name].i18n'
}
```
### License
MIT (http://www.opensource.org/licenses/mit-license.php)
================================================
FILE: index.js
================================================
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Dan Abramov
Shamelessly based on bundle-loader by Tobias Koppers @sokra
*/
var path = require('path');
module.exports = function () {};
module.exports.pitch = function (remainingRequest) {
this.cacheable && this.cacheable();
var query = this.query.substring(1).split(','),
promiseLib = query[0],
bundleName = query[1] || '';
var filename = path.basename(remainingRequest);
var name = path.basename(remainingRequest, path.extname(filename));
bundleName = bundleName.replace(/\[filename\]/g, filename).replace(/\[name\]/g, name);
if (!promiseLib) {
throw new Error('You need to specify your Promise library of choice, e.g. require("promise?bluebird!./file.js")');
}
var result = [
(promiseLib !== 'global') ? 'var Promise = require(' + JSON.stringify(promiseLib) + ');\n' : '',
'module.exports = function () {\n',
' return new Promise(function (resolve) {\n',
' require.ensure([], function (require) {\n',
' resolve(require(', JSON.stringify('!!' + remainingRequest), '));\n',
' }' + (bundleName && (', ' + JSON.stringify(bundleName))) + ');\n',
' });\n',
'}'
];
return result.join('');
};
================================================
FILE: package.json
================================================
{
"name": "promise-loader",
"version": "1.0.0",
"author": {
"name": "Dan Abramov"
},
"description": "a webpack bundle-loader ripoff with promise interface",
"repository": {
"type": "git",
"url": "git://github.com/gaearon/promise-loader.git"
},
"licenses": [
{
"type": "MIT",
"url": "http://www.opensource.org/licenses/mit-license.php"
}
]
}
gitextract_k4fh87rh/ ├── .gitignore ├── README.md ├── index.js └── package.json
Condensed preview — 4 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (4K chars).
[
{
"path": ".gitignore",
"chars": 23,
"preview": "node_modules\n.DS_Store\n"
},
{
"path": "README.md",
"chars": 1848,
"preview": "## A sister of [bundle-loader](https://github.com/webpack/bundle-loader) with promise API\r\n\r\n### Usage\r\n\r\n[Documentation"
},
{
"path": "index.js",
"chars": 1287,
"preview": "/*\r\n MIT License http://www.opensource.org/licenses/mit-license.php\r\n Author Dan Abramov\r\n Shamelessly based on bundle-l"
},
{
"path": "package.json",
"chars": 391,
"preview": "{\n \"name\": \"promise-loader\",\n \"version\": \"1.0.0\",\n \"author\": {\n \"name\": \"Dan Abramov\"\n },\n \"description\": \"a web"
}
]
About this extraction
This page contains the full source code of the gaearon/promise-loader GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 4 files (3.5 KB), approximately 977 tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.