-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
now bundling browser-version with webpack
- Loading branch information
nash403
committed
Sep 20, 2016
1 parent
6bb8322
commit f5179ae
Showing
7 changed files
with
60 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "presets": [ "es2015"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
tests.js | ||
node_modules/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,23 @@ | ||
(function(){ | ||
// Utils | ||
const isFnCall = function (key){ | ||
if (typeof key !== 'string') return false; | ||
return key.slice(-2) === "()"; | ||
}; | ||
/* | ||
* @param {key} string concatenation of nested keys in this form: 'foo.bar.toto'. | ||
* You can even call a function if the last key ends with '()'. | ||
* @param {obj} the object we are accessing | ||
* @param {...args} a sequence of arguments that may be passed to the function we are calling | ||
* @return a nested value OR the result of a nested function OR undefined | ||
*/ | ||
myExport((key, obj, ...args) => { | ||
let splitted = key.split('.'); | ||
let lastkey = splitted.pop(); | ||
let isFnCallLastkey = isFnCall(lastkey); | ||
lastkey = isFnCallLastkey ? lastkey.slice(0,-2) : lastkey; | ||
let beforelast = splitted.reduce((a,b) => { | ||
return a && a[b]; | ||
}, obj); | ||
return beforelast && (typeof beforelast === 'object') && (isFnCallLastkey ? beforelast[lastkey](...args) : beforelast[lastkey]); | ||
}, true, 'getSafe'); | ||
// Utils | ||
const isFnCall = function (key){ | ||
if (typeof key !== 'string') return false; | ||
return key.slice(-2) === "()"; | ||
}; | ||
|
||
// Exports | ||
function myExport(exported, isDefault, name) { | ||
if (!name) throw "myExport function: <name> mustn't be undefined"; | ||
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') { | ||
if (isDefault) { | ||
module.exports = exported; | ||
} else { | ||
module.exports[name] = exported; | ||
} | ||
} | ||
else { | ||
window[name] = exported; | ||
} | ||
}; | ||
})(); | ||
/* | ||
* @param {key} string concatenation of nested keys in this form: 'foo.bar.toto'. | ||
* You can even call a function if the last key ends with '()'. | ||
* @param {obj} the object we are accessing | ||
* @param {...args} a sequence of arguments that may be passed to the function we are calling | ||
* @return a nested value OR the result of a nested function OR undefined | ||
*/ | ||
module.exports = (key, obj, ...args) => { | ||
let splitted = key.split('.'); | ||
let lastkey = splitted.pop(); | ||
let isFnCallLastkey = isFnCall(lastkey); | ||
lastkey = isFnCallLastkey ? lastkey.slice(0,-2) : lastkey; | ||
let beforelast = splitted.reduce((a,b) => { | ||
return a && a[b]; | ||
}, obj); | ||
return beforelast && (typeof beforelast === 'object') && (isFnCallLastkey ? beforelast[lastkey](...args) : beforelast[lastkey]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
var webpack = require('webpack'); | ||
|
||
module.exports = { | ||
entry: "./index", | ||
output: { | ||
path: __dirname, | ||
filename: "./browser-version/get-safe.js", | ||
library: "getSafe", | ||
libraryTarget: 'umd' | ||
}, | ||
resolve: { | ||
extensions: ["",".js"] | ||
}, | ||
module: { | ||
loaders: [{ | ||
test: /\.js$/, | ||
exclude: [/node_modules/], // exclude unwanted js files | ||
loader: 'babel' // 'babel-loader' is also valid name | ||
}] | ||
}, | ||
plugins: [ | ||
new webpack.optimize.UglifyJsPlugin() // Plugin for js minification | ||
] | ||
} |