Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulp-es6-amd

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-es6-amd

Emits the entire dependency tree of one or more AMD modules, from leaves to root, and names anonymous modules

  • 0.6.0
  • latest
  • npm
  • Socket score

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

gulp-amd-optimizer

Emits the entire dependency tree of one or more AMD modules, from leaves to root, and names anonymous modules

This module does not combine the modules into a single file. It is up to you to decide how to concat/minify the modules, using for example uglify, closure-compiler or just concatenating it together.

Install

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

Usage

var gulp = require('gulp');
var amdOptimize = require('gulp-amd-optimizer');
var concat = require('gulp-concat');

var requireConfig = {
  baseUrl: __dirname
};
var options = {
  umd: false
};

gulp.task('default', function () {
  return gulp.src('src/*.js', {base: requireConfig.baseUrl})
    .pipe(amdOptimize(requireConfig, options))
    .pipe(concat('modules.js'))
    .pipe(gulp.dest('dist'));
});

Output

gulp-amd-optimizer accepts JS files containing one or more AMD modules. Anonymous modules are given the name of the file (including the path, relative to the baseUrl, without the .js extension). Dependencies of modules are found and a full dependency tree is constructed. Finally the tree is sorted in topological order (from leaves to root nodes) and each module is emitted as a single file.

This plugin does not attempt to concat the files. This is the job of other plugins.

Config

The amdOptimizer method takes the RequireJS configuration as its first argument, as described in the RequireJS documentation, with some slight differences:

  • baseUrl: string The path from which modules are loaded. RequireJS documentation
  • exclude: [string] List of modules and folders NOT to load.

Options

The second argument to amdOptimizer is optional and can be used to change the way modules are found and named. It consists of the following options:

Sourcemap

gulp-amd-optimzer supports the gulp-sourcemaps plugin. The example below shows how sourcemaps can be used.

var gulp = require('gulp');
var amdOptimize = require('gulp-amd-optimizer');
var concat = require('gulp-concat');
var sourcemap = require('gulp-sourcemaps');

gulp.task('default', function () {
  return gulp.src('src/*.js', { base: amdConfig.baseUrl })
    .pipe(sourcemap.init())
    .pipe(amdOptimize(amdConfig))
    .pipe(concat('modules.js'))
    .pipe(sourcemap.write('./', { includeContent: false, sourceRoot: '../src' }))
    .pipe(gulp.dest('dist'));
});

var amdConfig = {
  baseUrl: 'src',
  path:{
    'lib': '../lib'
  }
  exclude: [
    'jQuery'
  ]
};

Sourcemaps can be difficult to get right, so it is a good idea to follow these rules:

  • The base option passed to gulp.src should be the same as baseUrl in the amdConfig.
  • The sourcemap should be written to the same folder (./) as the output.
  • The sourceRoot should be the relative path from the destination folder (the argument to gulp.dest) to the base.

License

MIT © Marius Gundersen

Keywords

FAQs

Package last updated on 13 Nov 2017

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