Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jdeagle/f0b5a5e026318aff2fc6 to your computer and use it in GitHub Desktop.
Save jdeagle/f0b5a5e026318aff2fc6 to your computer and use it in GitHub Desktop.

Revisions

  1. @malte-wessel malte-wessel revised this gist Sep 17, 2014. 2 changed files with 3 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion browserify-replace-underscore-with-lodash-globally.md
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,7 @@ browserify({
    These days, `underscore`, `backbone` and `backbone.marionette` support CommonJS. Shimming these packages is not necessary anymore. But that also means, that you have no control over the package's dependencies.
    Luckily, there exists a browserify transform called [aliasify](https://github.com/benbria/aliasify). This package will transform the require paths of your **local modules**. If you want the transform to operate on your whole bundle, you need to use it directly within your browserify task, since you can not configure global transforms in a `package.json` like you can with ordinary transforms.

    Have a look at `browserify-task.js`. The aliasify transform is applied globally. The aliasify transform can still be configurated within your `package.json`. Note: the browserify transform field should not contain aliasify, since it will only be used on *local modules*.
    Have a look at `browserify-task.js`. The aliasify transform is applied globally. The aliasify transform can still be configurated within your `package.json`. Note: the browserify transform field should not contain aliasify, since it will only operate on your *local modules*.

    If you want to replace all of the underscore requires with lodash, you can configure aliasify like:
    ```json
    3 changes: 2 additions & 1 deletion browserify-task.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    var browserify = require('gulp-browserify');
    var browserify = require('gulp-browserify'),
    aliasify = require('aliasify');

    var bundler = browserify({
    // Configure browserify
  2. @malte-wessel malte-wessel revised this gist Sep 17, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion browserify-replace-underscore-with-lodash-globally.md
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,7 @@ browserify({
    These days, `underscore`, `backbone` and `backbone.marionette` support CommonJS. Shimming these packages is not necessary anymore. But that also means, that you have no control over the package's dependencies.
    Luckily, there exists a browserify transform called [aliasify](https://github.com/benbria/aliasify). This package will transform the require paths of your **local modules**. If you want the transform to operate on your whole bundle, you need to use it directly within your browserify task, since you can not configure global transforms in a `package.json` like you can with ordinary transforms.

    Have a look at `browserify-task.js`. The aliasify transform is applied globally. The aliasify transform can still be configurated within your `package.json`. Note: the browserify transform field should not contain the aliasify, since it will only be used for *local modules*.
    Have a look at `browserify-task.js`. The aliasify transform is applied globally. The aliasify transform can still be configurated within your `package.json`. Note: the browserify transform field should not contain aliasify, since it will only be used on *local modules*.

    If you want to replace all of the underscore requires with lodash, you can configure aliasify like:
    ```json
  3. @malte-wessel malte-wessel revised this gist Sep 17, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion browserify-replace-underscore-with-lodash-globally.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    If you are using `backbone` (and `backbone.marionette`) in a project, you will likely run into issues with `underscore` (at least if you manage your dependencies with npm). Each package, that has underscore as a dependency, will require its own version of `underscore` (making your bundle file contain multiple versions of `underscore`). **Back in the days**, you could shim `backbone` and `underscore` like:
    If you are using `backbone` (and `backbone.marionette`) in a `browserify` managed project, you will likely run into issues with `underscore` (at least if you manage your dependencies with npm). Each package, that has underscore as a dependency, will require its own version of `underscore` (making your bundle file contain multiple versions of `underscore`). **Back in the days**, you could shim `backbone` and `underscore` like:

    ```javascript

  4. @malte-wessel malte-wessel renamed this gist Sep 17, 2014. 1 changed file with 0 additions and 0 deletions.
  5. @malte-wessel malte-wessel revised this gist Sep 17, 2014. 1 changed file with 6 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions browserify-task.js
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,10 @@
    var browserify = require('gulp-browserify');

    var bundler = browserify({
    // Configure browserify
    // Configure browserify
    });

    bundler
    // Global aliases (e.g. replaces underscore with lodash)
    .transform({global: true}, aliasify)
    .bundle();
    // Global aliases (e.g. replaces underscore with lodash)
    .transform({global: true}, aliasify)
    .bundle();
  6. @malte-wessel malte-wessel revised this gist Sep 17, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion -replace-underscore-with-lodash-globally.md
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@ browserify({
    ```

    These days, `underscore`, `backbone` and `backbone.marionette` support CommonJS. Shimming these packages is not necessary anymore. But that also means, that you have no control over the package's dependencies.
    Luckily, there exists a browserify transform called [aliasify](https://github.com/benbria/aliasify). This package will transform the require paths for your **local modules**. If you want the transform to operate on your whole bundle, you need to use it directly within your browserify task, since you can not configure global transforms in a `package.json` like you can with ordinary transforms.
    Luckily, there exists a browserify transform called [aliasify](https://github.com/benbria/aliasify). This package will transform the require paths of your **local modules**. If you want the transform to operate on your whole bundle, you need to use it directly within your browserify task, since you can not configure global transforms in a `package.json` like you can with ordinary transforms.

    Have a look at `browserify-task.js`. The aliasify transform is applied globally. The aliasify transform can still be configurated within your `package.json`. Note: the browserify transform field should not contain the aliasify, since it will only be used for *local modules*.

  7. @malte-wessel malte-wessel renamed this gist Sep 17, 2014. 1 changed file with 0 additions and 0 deletions.
  8. @malte-wessel malte-wessel revised this gist Sep 17, 2014. No changes.
  9. @malte-wessel malte-wessel renamed this gist Sep 17, 2014. 1 changed file with 0 additions and 0 deletions.
  10. @malte-wessel malte-wessel revised this gist Sep 17, 2014. 2 changed files with 2 additions and 1 deletion.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -16,6 +16,7 @@ browserify({
    'underscore': '_'
    }
    }
    }
    }
    });
    ```
    2 changes: 1 addition & 1 deletion browserify-task.js
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,6 @@ var bundler = browserify({
    });

    bundler
    // Global aliases (e.g. replaces underscore with lodash)
    // Global aliases (e.g. replaces underscore with lodash)
    .transform({global: true}, aliasify)
    .bundle();
  11. @malte-wessel malte-wessel revised this gist Sep 17, 2014. 1 changed file with 6 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -27,11 +27,13 @@ Have a look at `browserify-task.js`. The aliasify transform is applied globally.

    If you want to replace all of the underscore requires with lodash, you can configure aliasify like:
    ```json
    "aliasify": {
    "aliases": {
    "underscore": "./node_modules/lodash/dist/lodash.underscore.js"
    {
    "aliasify": {
    "aliases": {
    "underscore": "./node_modules/lodash/dist/lodash.underscore.js"
    }
    }
    },
    }
    ```


  12. @malte-wessel malte-wessel revised this gist Sep 17, 2014. 1 changed file with 12 additions and 2 deletions.
    14 changes: 12 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,17 @@ browserify({
    ```

    These days, `underscore`, `backbone` and `backbone.marionette` support CommonJS. Shimming these packages is not necessary anymore. But that also means, that you have no control over the package's dependencies.
    Luckily, there exists a browserify transform called [aliasify](https://github.com/benbria/aliasify). This package will transform the require paths for your *local modules*. If you want the transform to operate on your whole bundle, you need to use it directly within your browserify task, since you can not configure global transforms in a `package.json` like you can with ordinary transforms.
    Luckily, there exists a browserify transform called [aliasify](https://github.com/benbria/aliasify). This package will transform the require paths for your **local modules**. If you want the transform to operate on your whole bundle, you need to use it directly within your browserify task, since you can not configure global transforms in a `package.json` like you can with ordinary transforms.

    Have a look at `browserify-task.js`. The aliasify transform is applied globally. The aliasify transform can still be configurated within your `package.json`. Note: the browserify transform field should not contain the aliasify, since it will only be used for *local modules*.

    If you want to replace all of the underscore requires with lodash, you can configure aliasify like:
    ```json
    "aliasify": {
    "aliases": {
    "underscore": "./node_modules/lodash/dist/lodash.underscore.js"
    }
    },
    ```

    Have a look at `browserify-task.js`. The aliasify transform is applied globally.

  13. @malte-wessel malte-wessel revised this gist Sep 17, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    If you are using `backbone` (and `backbone.marionette`) in a project, you will likely run into issues with `underscore` (at least if you manage your dependencies with npm). Each package, that has underscore as a dependency, will require its own version of `underscore` (making your bundle file contain multiple versions of `underscore`), *Back in the days*, you could shim `backbone` and `underscore` like:
    If you are using `backbone` (and `backbone.marionette`) in a project, you will likely run into issues with `underscore` (at least if you manage your dependencies with npm). Each package, that has underscore as a dependency, will require its own version of `underscore` (making your bundle file contain multiple versions of `underscore`). **Back in the days**, you could shim `backbone` and `underscore` like:

    ```javascript

  14. @malte-wessel malte-wessel revised this gist Sep 17, 2014. 1 changed file with 20 additions and 14 deletions.
    34 changes: 20 additions & 14 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,21 +1,27 @@
    If you are using backbone (and backbone.marionette) in a project, you will likely run into issues with underscore (at least if you manage your dependencies with npm). Each package, that has underscore as a dependency, will require its own version of underscore (making your bundle file contain multiple versions of underscore), *Back in the days*, you could shim backbone and underscore like:
    If you are using `backbone` (and `backbone.marionette`) in a project, you will likely run into issues with `underscore` (at least if you manage your dependencies with npm). Each package, that has underscore as a dependency, will require its own version of `underscore` (making your bundle file contain multiple versions of `underscore`), *Back in the days*, you could shim `backbone` and `underscore` like:

    ```javascript

    browserify({
    shim: {
    'underscore': {
    path: './node_modules/underscore/underscore.js',
    exports: '_'
    },
    'backbone': {
    path: './node_modules/backbone/backbone.js',
    exports: 'Backbone',
    depends: {
    'jquery': '$',
    'underscore': '_'
    }
    }
    }
    'underscore': {
    path: './node_modules/underscore/underscore.js',
    exports: '_'
    },
    'backbone': {
    path: './node_modules/backbone/backbone.js',
    exports: 'Backbone',
    depends: {
    'jquery': '$',
    'underscore': '_'
    }
    }
    }
    });
    ```

    These days, `underscore`, `backbone` and `backbone.marionette` support CommonJS. Shimming these packages is not necessary anymore. But that also means, that you have no control over the package's dependencies.
    Luckily, there exists a browserify transform called [aliasify](https://github.com/benbria/aliasify). This package will transform the require paths for your *local modules*. If you want the transform to operate on your whole bundle, you need to use it directly within your browserify task, since you can not configure global transforms in a `package.json` like you can with ordinary transforms.

    Have a look at `browserify-task.js`. The aliasify transform is applied globally.

  15. @malte-wessel malte-wessel renamed this gist Sep 17, 2014. 1 changed file with 0 additions and 0 deletions.
  16. @malte-wessel malte-wessel created this gist Sep 17, 2014.
    8 changes: 8 additions & 0 deletions browserify-task.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    var bundler = browserify({
    // Configure browserify
    });

    bundler
    // Global aliases (e.g. replaces underscore with lodash)
    .transform({global: true}, aliasify)
    .bundle();
    21 changes: 21 additions & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    {
    "browserify": {
    "transform": []
    },
    "aliasify": {
    "aliases": {
    "underscore": "./node_modules/lodash/dist/lodash.underscore.js"
    }
    },
    "dependencies": {
    "backbone": "^1.1.2",
    "backbone.marionette": "^2.2.0",
    "backbone.wreqr": "^1.3.1",
    "jquery": "^2.1.1",
    "lodash": "^2.4.1",
    },
    "devDependencies": {
    "aliasify": "^1.4.0",
    "browserify": "^5.11.1",
    }
    }
    21 changes: 21 additions & 0 deletions replace-underscore-with-lodash-globally.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    If you are using backbone (and backbone.marionette) in a project, you will likely run into issues with underscore (at least if you manage your dependencies with npm). Each package, that has underscore as a dependency, will require its own version of underscore (making your bundle file contain multiple versions of underscore), *Back in the days*, you could shim backbone and underscore like:

    ```javascript

    browserify({
    shim: {
    'underscore': {
    path: './node_modules/underscore/underscore.js',
    exports: '_'
    },
    'backbone': {
    path: './node_modules/backbone/backbone.js',
    exports: 'Backbone',
    depends: {
    'jquery': '$',
    'underscore': '_'
    }
    }
    }
    });