gulp-requirejs-release
v1.0.6
Published
- A gulp plugin. - The project Use `requirejs`. - Build release environment.
Downloads
2
Maintainers
Readme
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
- Import html files into html files.
- What is this ?
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
| Option| Type| Default| Description |
| ------|-----|--------|--------------|
| basePath
| String | ./
| |
| destPath
| String | ./
| |
| copy
| Object | | Plugin Options |
| linter
| Object | | Plugin Options|
| replace
| Object | | Plugin Options |
| optimize
| Object | | Plugin Options |
| sourcemaps
| Object or Boolean | | Plugin Options |
Copy options
| Name | Type| Description |
| ------|-----|--------------|
| src
| String or Array | |
Linter options
| Name | Type| Description |
| ------|-----|--------------|
| src
| String or Array | |
| options
| Object | |
Replace options
| Name | Type| Description |
| ------|-----|--------------|
| basePath
| String | |
| destPath
| String | |
| list
| Array | [ {src: '**.*', replace: ['str1', 'str2'], dest: ''} ]
|
| callback
| Function* | |
Optimize options
| Name | Type| Description |
| ------|-----|--------------|
| basePath
| String | |
| src
| String or Array | |
| options
| Object or Function | |
| dest
| String or Function | |
Sourcemaps options
| Name | Type| Description |
| ------|-----|--------------|
| | Boolean | Default is false
|
| initOptions
| Object | |
| writePath
| String | |
| writeOptions
| Object | |
Copyright © 2018 Vic Yang