Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulp-file-contents-to-keys

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-file-contents-to-keys

Put some files, output ES6 exports of their contents.

  • 0.2.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

gulp-file-contents-to-modules

Input some files, output ES6 exports of their contents. Very helpful when working with HTML template files, so each of them could be imported using ES6 syntax.

I recommend using rollup for ES6 modules bundling.

Installation

$ npm install gulp-file-contents-to-modules

How it works

Given a nested directory of files like so,

my-files
├── bar.html
├── foo.html
└── my-folder
    └── baz.html

gulp-file-contents-to-modules reads in each file, and outputs a single JSON file representing the contents of each file within the folder. When a directory is encountered, it becomes a nested object within the JSON blob, like so:

export var bar = "This is bar.";
export var foo = "This is foo.\r\n";
export var my-folder__baz = "This is baz.\r\n";

How to Use

For example, to read in the contents of the my-files folder and output dist/contents.js, simply add the following gulp task inside gulpfile.js:

var gulp    = require('gulp');
var fc2modules = require('gulp-file-contents-to-modules');

gulp.task('default', function() {
  gulp.src('templates/**/*')
      .pipe(fc2modules({
            compile : true, // 'true' (use '_.template') or pass any other string to wrap the template string with
            minify  : true, // remove new lines and whitespaces between tags
      })
      .pipe(gulp.dest('./dist/'));
});

Simply run the following and you're done:

$ gulp

License

MIT

FAQs

Package last updated on 26 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc