A gulp plugin to add identifier to AMD modules.
Use this plugin to give an identifier to your AMD modules when writing your own optimizer.
$ npm install --save-dev gulp-amd-idfy
var gulp = require('gulp');
var idfy = require('gulp-amd-idfy');
gulp.task('default', function () {
return gulp.src('scripts/**/*.js')
.pipe(idfy())
.pipe(gulp.dest('dist'));
});
Notes:
- The module identifier depends on the file name and path.
- The plugin does not add an identifier if there is already one.
- The
define()
must be at the root of the javascript file, it cannot be enclosed in another function but it can be preceded by other functions, call, comments or directives such as'use strict'
.
Source files:
├── gulpfile.js
└── scripts
├── a
│ └── module2.js
├── b
│ └── module3.js
└── module1.js
gulp task:
gulp.src('scripts/**/*.js')
.pipe(idfy())
.pipe(concat('all.js'))
.pipe(gulp.dest('dist'));
result:
$ cat dist/all.js
define("module1", function () {
return 'module1';
});
define("a/module2", function () {
return 'module2';
});
define("b/module3", function () {
return 'module3';
});
MIT © Philippe FERDINAND