npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-requirejs-optimize

v1.3.0

Published

RequireJS optimizer plugin for gulp

Downloads

7,146

Readme

gulp-requirejs-optimize

Build Status npm version Coverage Status Dependency Status

Optimize AMD modules in javascript files using the requirejs optimizer.

Install

$ npm install --save-dev gulp-requirejs-optimize

Usage

Simple

var gulp = require('gulp');
var requirejsOptimize = require('gulp-requirejs-optimize');

gulp.task('scripts', function () {
	return gulp.src('src/main.js')
		.pipe(requirejsOptimize())
		.pipe(gulp.dest('dist'));
});

Custom options

gulp-requirejs-optimize accepts almost all of the same options as r.js optimize (see below).

var gulp = require('gulp');
var requirejsOptimize = require('gulp-requirejs-optimize');

gulp.task('scripts', function () {
	return gulp.src('src/main.js')
		.pipe(requirejsOptimize({
			optimize: 'none',
			insertRequire: ['foo/bar/bop'],
		}))
		.pipe(gulp.dest('dist'));
});

Multiple Modules

Each file passed to the plugin is optimized as a separate module.

var gulp = require('gulp');
var requirejsOptimize = require('gulp-requirejs-optimize');

gulp.task('scripts', function () {
	return gulp.src('src/modules/*.js')
		.pipe(requirejsOptimize())
		.pipe(gulp.dest('dist'));
});

Options generating function

Options can also be specified in the form of an options-generating function to generate custom options for each file passed. This can be used to apply custom logic while optimizing multiple bundles or modules in an app.

var gulp = require('gulp');
var requirejsOptimize = require('gulp-requirejs-optimize');

gulp.task('scripts', function () {
	return gulp.src('src/modules/*.js')
		.pipe(requirejsOptimize(function(file) {
			return {
				name: '../vendor/bower/almond/almond',
				optimize: 'none',
				useStrict: true,
				baseUrl: 'path/to/base',
				include: 'subdir/' + file.relative
			};
		}))
		.pipe(gulp.dest('dist'));
});

Sourcemaps support

The plugin supports gulp-sourcemaps only if preserveLicenseComments is set to false, as described in the r.js docs. If preserveLicenseComments is not specified and the gulp-sourcemaps plugin is detected, the plugin will automatically set preserveLicenseComments to false.

var gulp = require('gulp');
var requirejsOptimize = require('gulp-requirejs-optimize');
var sourcemaps = require('gulp-sourcemaps');

gulp.task('scripts', function () {
	return gulp.src('src/main.js')
		.pipe(sourcemaps.init())
		.pipe(requirejsOptimize())
		.pipe(sourcemaps.write())
		.pipe(gulp.dest('dist'));
});

API

requirejsOptimize(options)

options

Options are the same as what is supported by the r.js optimizer except for out, modules, and dir.

The options parameter can be specified as a static object or an options-generating function. Options-generating functions are passed a file object and are expected to generate an options object.

Differences From r.js

out

r.js supports out as a string describing a path or a function which processes the output. Since we need to pass a virtual file as output, we only support the string version of out.

modules and dir

r.js supports an array of modules to optimize multiple modules at once, using the dir parameter for the output directory. The same thing can be accomplished with this plugin by passing the main file of each module as input to the plugin. gulp.dest can be used to specify the output directory.

This means an r.js config file for optimizing multiple modules that looks like this:

{
	"baseUrl": "src/modules",
	"dir": "dist",
	"modules": [{
		"name": "one"
	}, {
		"name": "two"
	}]
}

Would look like this as a gulp task with this plugin:

gulp.task('scripts', function () {
	return gulp.src('src/modules/*.js')
		.pipe(requirejsOptimize())
		.pipe(gulp.dest('dist'));
});

License

MIT © Jonathan Lounsbury