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

@exuanbo/gulp-inject-inline

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

@exuanbo/gulp-inject-inline

A javascript, stylesheet and webcomponent inline injection plugin for Gulp.js

  • 1.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
Maintainers
1
Weekly downloads
 
Created
Source

@exuanbo/gulp-inject-inline

A javascript, stylesheet and webcomponent inline injection plugin for Gulp.js

npm (scoped) JavaScript Style Guide Travis (.com) David License

Table of Contents

Description

@exuanbo/gulp-inject-inline transforms content of each source file to a string and injects each transformed string into placeholders in the target stream files.

This plugin does not do any minification to source files, so whitespaces will be preserved. It's better to use it after transformations like gulp-uglify-es or gulp-clean-css.

Installation

Install @exuanbo/gulp-inject-inline as a development dependency

npm install --save-dev @exuanbo/gulp-inject-inline

Usage

Injection placeholders are comments as html syntax <!-- inject-inline: filePath --> and css/js syntax /* inject-inline: filePath */

By default the injected file path is relative to each target file's cwd. If the provided path starts with /, it will be considered relative to the directory of gulpfile.js

Example

Project structure

├── src
│   ├── css
│   │   └── style.css
│   ├── js
│   │   └── script.js
│   ├── template
│   │   └── head.html
│   └── index.html
└── gulpfile.js

Target file src/index.html

<html>
  <head>
    <!-- inject-inline: /src/template/head.html -->
    <style>
      /* inject-inline: ./css/style.css */
    </style>
    <script>
      /*inject-inline:js/script.js*/
    </script>
  </head>
  <body>
    <h1>Hello World!</h1>
  </body>
</html>

gulpfile.js

const gulp = require('gulp')
const injectInline = require('@exuanbo/gulp-inject-inline')

gulp.task('inject', () => {
  return gulp.src('src/index.html')
    .pipe(injectInline())
    .pipe(gulp.dest('dist'))
})

dist/index.html after running gulp inject

<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <meta title="test">
    <style>
      body {
        background-color: #333;
      }

      h1 {
        color: #EEE;
      }
    </style>
    <script>
      console.log('foobar')
    </script>
  </head>
  <body>
    <h1>Lorem Ipsum</h1>
  </body>
</html>

Indentation

Note that existing indentation won't be preserved.

Target file src/index.html

<html>
  <head>
    <style>
      /* inject-inline: ./css/style.css */
    </style>
  </head>
  <body>
    <h1>Hello World!</h1>
  </body>
</html>

Source file src/css/style.css

body {
  background-color: #333;
}

h1 {
  color: #EEE;
}

dist/index.html

<html>
  <head>
    <style>
      body {
  background-color: #333;
}

h1 {
  color: #EEE;
}
    </style>
  </head>
  <body>
    <h1>Hello World!</h1>
  </body>
</html>

License

MIT

Donate

Buy Me A Coffee

Keywords

FAQs

Package last updated on 06 Jun 2020

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