-
Notifications
You must be signed in to change notification settings - Fork 712
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
98777c5
commit 186b7cb
Showing
1 changed file
with
35 additions
and
1 deletion.
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 |
---|---|---|
@@ -1,7 +1,41 @@ | ||
# Working with module bundlers | ||
|
||
## Browserify | ||
todo | ||
|
||
### Reflect-Metadata | ||
The source from the reflect-metadata module contains a require('crypto') statement, | ||
which will pull additional node-builtin dependencies into your final bundle. | ||
This is about 0.6MB, way too much for a **browser build**. | ||
|
||
To workaround this issue add an init task in your gulp or grunt file to modify the library directly. Then browserify-shim the modified library. | ||
Below is an example for using gulp, you can execute multiple tasks within one tasks by using event-stream. | ||
|
||
gulp.task("init", function(done){ | ||
var tasks = []; | ||
|
||
tasks.push( | ||
gulp.src(["node_modules/reflect-metadata/Reflect.js"]) | ||
.pipe(replace(/var nodeCrypto = isNode && require\("crypto"\);/g, "var nodeCrypto = false;")) | ||
.pipe(gulp.dest("src/ts/libs")) | ||
); | ||
|
||
return es.merge(tasks).on("end", done); | ||
}); | ||
|
||
Then in your package.json file, add a browserify-shim to the modified library: | ||
|
||
dependencies:{ | ||
"browserify-shim": "latest" | ||
} | ||
"browser": { | ||
"reflect-metadata": "./src/ts/libs/Reflect.js" | ||
}, | ||
"browserify": { | ||
"transform" : ["browserify-shim" ] | ||
} | ||
|
||
Make the init task a dependency to run before your main task. | ||
You can then **require("reflect-metadata")** or **import "reflect-metadata"** in your inversify.config.ts/js file as usual. | ||
|
||
## Webpack | ||
todo |