New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gulp-sort-amd

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-sort-amd

Sorts files in stream by dependencies defined according to AMD/requirejs spec.

  • 0.9.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

gulp-sort-amd

Sorts files in stream by dependencies defined according to the AMD/require.js specification. Used in conjunction with gulp-concat to combine files in the correct order, so dependent files execute first when loaded.

This plugin allows you to use your modules without adding the weight of requirejs to your website. Instead, you can use a stupid simple define/require shim (found in /shim). In order to use it though, you must name all your modules, or it can't be retrieved from the hash map. It will collide with any AMD library, but it will still work with any modules using UMD wrappers.

The greatest benefit of this is the ability to require modules from outside the bundle itself, thereby allowing you to split bundles up per page (or even within a single page app) and still allow modules across bundles to communicate with each other without requirejs.

This assumes you are concatenating all of your scripts into various bundles, as this method prevents dynamic loading of individual modules (which I saw as a plus since it's best to bundle anyway). But because you can access modules in one bundle from another, you can dynamically load that bundle with a single, simple XHR call. This is ideal for single page apps that have large sections of content that you only want to load if the user accesses them, which is exactly the use case I built this for.

Install

$ npm install --save-dev gulp-sort-amd

Usage

Gulpfile

var gulp = require('gulp');
var sortAmd = require('gulp-sort-amd');
var sourcemaps = require('gulp-sourcemaps');
var concat = require('gulp-concat');

gulp.task('default', function () {
	return gulp.src('src/**/*.js')
		.pipe(sortAmd())
		.pipe(sourcemaps.init())
        .pipe(concat('scripts.js'))
        .pipe(sourcemaps.write('./'))
		.pipe(gulp.dest('dist'));
});

Source file

Named modules with dependencies as a parameter:

define('a', ['sub/b', '../c'], function(b, c) {
	// hot sauce
});

Unnamed modules in the commonJS style:

define(function() {
	var b = require('b');
	var c = require('c');
});

And everything else amdetective supports.

License

gulp-sort-amd is MIT licensed. Feel free to use it, contribute or spread the word. Created by Corey Birnbaum. Based off of gulp-deps-order by Petr Nevyhoštěný (Twitter).

Keywords

FAQs

Package last updated on 22 Nov 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc