Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including gulp-requirejs-release with all npm packages installed. Try it out:

var gulpRequirejsRelease = require("gulp-requirejs-release")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

gulp-requirejs-release v1.0.6

gulp-requirejs-release

  • A gulp plugin.
  • The project Use requirejs.
  • Build release environment.

Usage

Install

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

Gulpfile

var gulp = require('gulp')
var requirejsRelease = require('gulp-requirejs-release')

Gulp Tasks

gulp.task('build', function() {
  requirejsRelease({
    // To do something...
  })
})

copy

Copy source files to new destination.

requirejsRelease({
  copy: {
    src: './src/**',
    dest: './dest'
  }
})

linter

requirejsRelease({
  linter: {
    src: 'src/**/*.js',
    options: { linter: 'some-jshint-module' } // Default is "jshint"
  }
})

replace

requirejsRelease({
  replace: {
    list: [{
      src: '*.html',
      replace: ['__VERSION__', '2018'],
    }, {
      src: 'css/*.css',
      replace: [/\.\.\/img\/(.+?)\.(jpg|png)/g, function(match, p1) {
        return '//IMG_HOST/img/' + p1 + '.' + match.split('.').pop()
      }],
      dest: 'css'
    }]
  }
})

requirejs-optimize

Optimize AMD modules in javascript files using the requirejs optimizer.

Simple

requirejsRelease({
  optimize: {
    src: 'src/js/*.js',
    dest: './dist'
  }
})

Custom options

Accepts almost all of the same options as r.js optimize (see below).

requirejsRelease({
  optimize: {
    src: 'src/js/*.js',
    options: {
        optimize: 'none',
        insertRequire: ['foo/bar/bop']
    },
    dest: function(destPath, filePath) {
      // Default is "./"
      return destPath
    }
  }
})

// Or
requirejsRelease({
  optimize: {
    src: 'src/js/*.js',
    options: function(file) {
      return {
        name: '../vendor/bower/almond/almond',
        optimize: 'none',
        useStrict: true,
        baseUrl: 'path/to/base',
        include: 'subdir/' + file.relative
      }
    },
    dest: function(destPath, filePath) {
      // Default is "./"
      return destPath
    }
  }
})

sourcemaps

Simple

requirejsRelease({
  optimize: {
    src: 'src/js/*.js',
    dest: './dist'
  },
  sourcemaps: true
})
  • Map file path: "./dist/*.js.map"

Custom options

requirejsRelease({
  optimize: {
    src: 'src/js/*.js',
    dest: './dist'
  },
  sourcemaps: {
    initOptions: {largeFile: true},
    writePath: '../maps',
    writeOptions: {addComment: false}
  }
})

html-imports

requirejsRelease({
  htmlImports: {
    src: 'src/*.html',
    componentsPath: './components/',
    template: {
      '_VERSION_': '2018'
    }
  }
})

Example

A complete example

gulpfile.js


// GulpRequirejsRelease options
var options = {
  basePath: './src/',
  destPath: './dest/',
  copy: {
    src: '**'
  },
  linter: {
    src: 'js/**/*.js'
  },
  replace: {
    list: [{
      src: '*.html',
      replace: ['__VERSION__', '2018'],
    }, {
      src: 'css/*.css',
      replace: [/\.\.\/img\/(.+?)\.(jpg|png)/g, function(match, p1) {
        return '//IMG_HOST/img/' + p1 + '.' + match.split('.').pop()
      }],
      dest: 'css'
    }]
  },
  optimize: {
    src: 'js/app/**/*.js',
    options: {
      baseUrl: './dest/',
      mainConfigFile: './dest/js/config.json'
    },
    dest: function(destPath, filePath) {
      return destPath + 'js/release'
    }
  },
  sourcemaps: true
}

// Task build
var gulp = require('gulp')
var requirejsRelease = require('gulp-requirejs-release')

gulp.task('build', function() {
  requirejsRelease(options)
})

Bash

$ gulp build

API

OptionTypeDefaultDescription
basePathString./
destPathString./
copyObjectPlugin Options
linterObjectPlugin Options
replaceObjectPlugin Options
optimizeObjectPlugin Options
sourcemapsObject or BooleanPlugin Options

Copy options

NameTypeDescription
srcString or Array

Linter options

NameTypeDescription
srcString or Array
optionsObject

Replace options

NameTypeDescription
basePathString
destPathString
listArray[ {src: '**.*', replace: ['str1', 'str2'], dest: ''} ]
callbackFunction*

Optimize options

NameTypeDescription
basePathString
srcString or Array
optionsObject or Function
destString or Function

Sourcemaps options

NameTypeDescription
BooleanDefault is false
initOptionsObject
writePathString
writeOptionsObject

Copyright © 2018 Vic Yang

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free