Skip to content
This repository has been archived by the owner on Jul 4, 2024. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cvgellhorn committed Apr 9, 2016
0 parents commit 69e1c8c
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.idea
.DS_Store

node_modules
bower_components
dist
log
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Christoph von Gellhorn

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# path-replace-loader for webpack

Path replace loader for [webpack](http://webpack.github.io/). Replace a specific base path with another for dynamic module loading. Great for large applications with locally overridable modules.

## Installation

`npm install path-replace-loader`

## Usage

[Read more about using loaders](http://webpack.github.io/docs/using-loaders.html)

#### Configuration

- <b>path:</b> Absolute original path to replace, e.g __dirname/app/core
- <b>replacePath:</b> Absolute replacement path, e.g __dirname/app/local

#### webpack config example

``` js
module.exports = {
module: {
loaders: [
{ test: /\.js$/, loader: 'path-replace?path=ORIGINAL_PATH&replacePath=REPLACE_PATH' },
]
}
};
```

#### Example

``` js
var authModule = require('app/core/modules/auth');
// Loader tries to load from local directory instead app/local/modules/auth
```

## Release History

- 0.1.0 - Initial release

## [MIT License](http://www.opensource.org/licenses/mit-license.php)
19 changes: 19 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var fs = require('fs');
var fileExists = require('file-exists');
var loaderUtils = require('loader-utils');

module.exports = function(source) {
this.cacheable && this.cacheable();
var options = loaderUtils.parseQuery(this.query);

if (this.resourcePath.indexOf(options.path) > -1) {
var newPath = this.resourcePath.replace(options.path, options.replacePath);
if (fileExists(newPath)) {
return fs.readFileSync(newPath);
}
}

return source;
};

module.exports.raw = true;
29 changes: 29 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "path-replace-loader",
"version": "0.1.0",
"description": "Path replace loader for webpack",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/cvgellhorn/path-replace-loader.git"
},
"keywords": [
"webpack",
"loader",
"path",
"replace"
],
"author": "Christoph von Gellhorn",
"license": "MIT",
"bugs": {
"url": "https://github.com/cvgellhorn/path-replace-loader/issues"
},
"homepage": "https://github.com/cvgellhorn/path-replace-loader#readme",
"dependencies": {
"file-exists": "^1.0.0",
"loader-utils": "^0.2.14"
}
}

0 comments on commit 69e1c8c

Please sign in to comment.