Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
MrFrankel committed Feb 15, 2018
1 parent fd30018 commit f0fd271
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
@@ -0,0 +1,3 @@
package-lock.json -diff
* text=auto
bin/* eol=lf
71 changes: 71 additions & 0 deletions .gitignore
@@ -0,0 +1,71 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env


/coverage
/dist
/local
/reports
/node_modules
.DS_Store
Thumbs.db
.idea
.vscode
*.sublime-project
*.sublime-workspace
78 changes: 78 additions & 0 deletions index.js
@@ -0,0 +1,78 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/

var path = require('path');

function accesorString(value) {
var childProperties = value.split(".");
var length = childProperties.length;
var propertyString = "global";
var result = "";

for (var i = 0; i < length; i++) {
if (i > 0)
result += "if(!" + propertyString + ") " + propertyString + " = {};\n";
propertyString += "[" + JSON.stringify(childProperties[i]) + "]";
}

result += "module.exports = " + propertyString;
return result;
}

module.exports = function (input) {
return input
};

module.exports.pitch = function (remainingRequest) {
// Change the request from an /abolute/path.js to a relative ./path.js
// This prevents [chunkhash] values from changing when running webpack
// builds in different directories.
// this.loadModule('@angular/core', (a,b,c,d) =>{debugger;});
if (this.query.modules && this.query.modules.length
&& this.query.modules
.every(mdl => !this._module.rawRequest.match(new RegExp(mdl)))) {
return;
}
const newRequestPath = remainingRequest.replace(
this.resourcePath,
'.' + path.sep + path.relative(this.context, this.resourcePath)
);

this.cacheable && this.cacheable();
if (!this.query || !this.query.namespace || !this.query.modules) throw new Error("query parameter is missing");
// Determine how to resolve the global object
let request = this._module.rawRequest.split('!');
request = request[request.length - 1].replace(/^@/i, '').replace(/\//g, '.');
const globalVar = `${this.query.namespace.replace(/^\?/i, '')}.${request}`;


/*
* Workaround until module.libIdent() in webpack/webpack handles this correctly.
*
* fixes:
* - https://github.com/webpack-contrib/expose-loader/issues/55
* - https://github.com/webpack-contrib/expose-loader/issues/49
*/
this._module.userRequest = this._module.userRequest + '-exposed';
return accesorString(globalVar) + " = " +
"require(" + JSON.stringify("-!" + newRequestPath) + ");";
};

module.exports.Externals = function (options) {
return function (context, request, callback) {
if (options.modules.every(mdl => !request.match(new RegExp(mdl)))){
return callback();
}
let newRequest = request.split('!');
newRequest = newRequest[newRequest.length - 1].replace(/^./i, '').split('/');
return callback(null, {
root: [options.namespace].concat(newRequest),
commonjs: request,
commonjs2: request,
amd: request
});

}
};
26 changes: 26 additions & 0 deletions package.json
@@ -0,0 +1,26 @@
{
"name": "share-loader",
"version": "0.0.1",
"author": "MFrankel",
"description": "share loader module for webpack",
"license": "MIT",
"main": "index.js",
"scripts": {},
"dependencies": {},
"devDependencies": {
},
"repository": {
"type": "git",
"url": "https://github.com/MrFrankel/share-loader.git"
},
"bugs": {
"url": "https://github.com/MrFrankel/share-loader/issues"
},
"homepage": "https://github.com/MrFrankel/share-loader",
"peerDependencies": {
"webpack": "^2.0.0 || ^3.0.0"
},
"engines": {
"node": ">= 4.3 < 5.0.0 || >= 5.10"
}
}

0 comments on commit f0fd271

Please sign in to comment.