New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

gulp-require-text-wrapper

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-require-text-wrapper

Creates an object with a text property containing a minified html string to be used in cross domain jsonp requests

latest
Source
npmnpm
Version
0.0.3
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

gulp-require-text-wrapper

Wraps HTML, JSON, CSS or Plain Text in an AMD module that can be consumed cross origin

Use

This gulp task is useful when if you have html, text, css, or json resources on a cdn that you otherwise wouldn't be able to access due to cross origin policies.

How it works

The gulp task will create an AMD define function which returns an object with a text attribute containing the resource as a string. If it is json you will need to parse it once loaded.

Sample Gulp Task

var gulp = require('gulp'),
    requireTextWrapper = require('gulp-require-text-wrapper');
    
gulp.task('require-wrap-html', function() {
  return gulp.src('./src/scripts/**/*.html')
    .pipe(requireTextWrapper())
    .pipe(rename(function(path) {
      path.extname += ".js"; // required!
    }))
    .pipe(gulp.dest('./src/scripts/'));
});

Use with Angular

Let's say you have a directive that needs to load a template from a remote cdn. Normally you would run into cross origin issues, since both angular's internal templateUrl property and requirejs's text plugin use xhr behind the scenes to load plain text resources.

By using this plugin you can wrap the resource as an AMD define function, require it as normal and access the resource via the return object's text property.

// Given a remote baseUrl of 'https://somecdn.com/templates/'
// ! The code below assumes the gulp task has been run on your resources and pushed to the remote server in its expected location

define(function(require) {
  'use strict';

  var template = require('./service-option.html'), // the actual request will be for 'https://somecdn.com/templates/service-option.html.js'
      serviceOptionController = require('./service-option-controller');

  var serviceOptionDirective = function() {
    return {
      restrict: 'E',
      scope: {
        service: '=',
        provider: '='
      },
      template: template.text,
      link: function(scope, element, attrs) {

      },
      controller: serviceOptionController
    }
  };

  return serviceOptionDirective;
});

FAQs

Package last updated on 22 Feb 2017

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