Extract YUI Loader meta from YUI modules
npm install gulp-yui-meta| Package | gulp-yui-meta |
| Description | Extract and concat YUI Loader meta data from YUI Modules |
| Node Version | ≥ 0.10 |
Extract meta from build YUI modules and concat to string representation of a
JavaScript object.
``javascript
var yuiMeta = require("gulp-yui-meta");
gulp.task("templates", function () {
return gulp.src("./lib/build//-min.js")
.pipe(yuiMeta("meta.js"))
.pipe(gulp.dest("./lib/build/meta"));
});
`
The supported parameters for the YUI module configuration can be found in the
YUI Documentation.
Note
This plugin accounts for functions inside the module configuration and keeps.json
them executable in the outputted JavaScript Object. If you want to save the meta
data as a file you have to parse them out before.
The following example of a gulp task assumes you have your build modules in./public/build
subfolders by module name in a folder:
`javascript
var yuiMeta = require("gulp-yui-meta"),
wrap = require("gulp-wrap"),
rename = require("gulp-rename"),
uglify = require("gulp-uglify");
gulp.task("meta", function () {
return gulp.src(["public/build//.js", "public/build//.css"])
// Concat the YUI module meta
.pipe(yuiMeta("meta.js"))
// Wrap the plain JavaScript hash inside a template to be able to
// include it as a script in the browser later on. You may change the
// template if you want to use the meta data as an AMD or RequireJS
// module instead.
.pipe(wrap("YUI.namespace(\"Env\").modules = <%= contents %>;\n"))
// Write the file to disk
.pipe(gulp.dest("public/build/meta"))
// Rename the file from meta.js to meta-min.js`
.pipe(rename({suffix: "-min"}))
// Minify the meta file
.pipe(uglify())
// Write the minified file to disk
.pipe(gulp.dest("public/build/meta"));
});
This task generates a meta folder inside your public/build folder, whichmeta.js
will contain a raw () and a minified (meta-min.js) version of your
YUI module meta.
Now you can use the meta file in your HTML like this:
`html``
...
...
MIT License