Last active
August 10, 2016 21:50
-
-
Save nucleartide/12d9fe7d7a7ce8477ddaaba0b27ce481 to your computer and use it in GitHub Desktop.
Ember.js: wrap node modules without using ember-browserify
This file contains hidden or 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
| #!/bin/sh | |
| # | |
| # This script imports node modules into your app without the use of | |
| # ember-browserify. To use, | |
| # | |
| # $ ./wrap_node_module.js | |
| # | |
| # (For the sake of an example, I use Lodash below.) | |
| # | |
| # After running the script, you can import the generated files into your | |
| # ember-cli-build.js: | |
| # | |
| # app.import('vendor/lodash.js') | |
| # app.import('vendor/shims/lodash.js') | |
| # | |
| # And now you can use lodash in your app! | |
| # | |
| # import _ from 'lodash' | |
| # | |
| # Feel free to modify the script below to your heart's content. | |
| # | |
| cat <<WTF >__module__.js | |
| module.exports = require('lodash') | |
| WTF | |
| if [ ! -d "node_modules/browserify" ]; then | |
| npm install browserify | |
| fi | |
| if [ ! -d "node_modules/babelify" ]; then | |
| npm install babelify | |
| fi | |
| if [ ! -d "node_modules/babel-preset-es2015" ]; then | |
| npm install babel-preset-es2015 | |
| fi | |
| browserify __module__.js -g [ babelify --presets [ es2015 ] ] -o vendor/lodash.js -s _ | |
| cat <<WTF >vendor/shims/lodash.js | |
| (function(){ | |
| var _ = window._ | |
| delete window._ | |
| define('lodash', [], function() { | |
| return { 'default': _ } | |
| }) | |
| })() | |
| WTF | |
| # cleanup | |
| rm __module__.js | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment