Exciting release!Introducing "safe npm". Learn more
Socket
Log inDemoInstall

gulp-wrap-file

Package Overview
Dependencies
2
Maintainers
1
Versions
7
Issues
File Explorer

Advanced tools

gulp-wrap-file

a gulp plugin for wrapping file content

    0.1.2latest
    GitHub

Version published
Maintainers
1
Weekly downloads
361
decreased by-2.96%

Weekly downloads

Readme

Source

gulp-wrap

NPM version Build Status

A gulp plugin to wrap a file contents.

Usage

Firstly, install gulp-wrap-file as a development dependency:

npm install gulp-wrap-file --save-dev

Then, add it into your gulpfile.js:

Wrap the commonjs contents with amd:

var wrapper = require("gulp-wrap-file"); gulp.src("./src/**/*.js") .pipe(wrap({type: 'amd'})) .pipe(gulp.dest("build"));

Wrap the contents by your file wrapper:

var wrap = require("gulp-wrap-file"); gulp.src("./src/**/*.js") .pipe(wrap({wrapper: 'define({file});'})) .pipe(gulp.dest("build"));

Wrap the contents with modName:

var wrap = require("gulp-wrap-file"); gulp.src("./src/**/*.js") .pipe(wrap({wrapper: 'define("src/{modName}",function((require, exports, module){ {file} }));'})) .pipe(gulp.dest("build"));

example

input

//input.js function foo() { console.log("hello world"); }

gulpfile.js

var wrap = require("gulp-wrap-file"); gulp.src("input.js") .pipe(wrap({wrapper: 'define("demo/{modName}",function((require, exports, module){ {file} }));'})) .pipe(gulp.dest("build"));

same to the wrapper for function

var wrap = require("gulp-wrap-file"); gulp.src("input.js") .pipe(wrap({wrapper: function(content, file){ return 'define("demo/'+file.modName+'",function((require, exports, module){ '+content+' }));' }})) .pipe(gulp.dest("build"));

output

define("demo/input",function((require, exports, module){ function foo() { console.log("hello world"); } }));

Parameters

type

Type: String

To wrap file with default support wrapper. On now, it only supports amd.

wrapper

Type: String or Function

The file wrapper to wrap your file content. You can get the file content and the pathname of the file. If wrapper is string, file content names {file}, short pathname of the file names {modName}. If wrapper is function, the arguments of the function are content of the file and the file object.

truncatePrefixLen

Type: Number

To truncate the name of the module prefix. For example, if the module name is path/to/foo. The value of truncatePrefixLen is 1, then the result will be to/foo.

nameReplacer

Type: Function

To handle the module name to what you want. With the config of nameReplacer, truncatePrefixLen will be disabled.

License

MIT License

Keywords

FAQs

Last updated on 22 Sep 2017

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket
support@socket.devSocket SOC 2 Logo

Product

  • Package Issues
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc