Socket
Socket
Sign inDemoInstall

gulp-preprocess-file

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-preprocess-file

A Gulp plugin for Preprocess files based off environment configuration. Based on Preprocess package


Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

gulp-preprocess-file

A Gulp plugin for Preprocess files based off environment configuration. Based on Preprocess package

Usage

Install

Use npm.

$ npm install --save-dev gulp-preprocess-file

html examples

Gulpfile

var preprocess = require('gulp-preprocess-file');
 
gulp.task('test:html', () => {
  gulp.src('./src/*.html')
    .pipe(preprocess({
      context: {
        NODE_ENV: 'production',
        title: 'this is a title',
        cdnFile: function(file) {
          return 'https://cdn.com/' + file
        }
      },
      extension: {
        srcDir: './src/'
      }
    }))
    .pipe(gulp.dest('dist/'))
})

html file

<body>
<h1><!-- @echo title --></h1>
<!-- @include ./text.html -->

<!-- @if NODE_ENV!='production' -->
<script src="./libs/jquery.min.js"></script>
<!-- @endif -->
<!-- @if NODE_ENV='production' -->
<script src="<!-- @exec cdnFile('dist/jquery.min.js') -->"></script>
<!-- @endif -->
<script>
var title = '<!-- @echo title -->' || 'Title'
</script>
</body>

Javascript/css examples

Gulpfile

var preprocess = require('gulp-preprocess-file');

gulp.task('test:js', () => {
  gulp.src(['./script/*.js'])
    .pipe(preprocess({
      context: {
        NODE_ENV: 'production',
        name: 'John',
      },
      extension: {
        type: 'js'
      }
    }))
    .pipe(gulp.dest('dist/'))
})

test.js file

var ENV = '/* @echo NODE_ENV */' || 'development'

/* @if NODE_ENV='production' **
console.log('production')
/* @endif */

// @if NODE_ENV='production'
console.log('my name is /* @echo name */')
// @endif

more: preprocess#configuration

API

preprocess(options)

options

Type: Object

more: preprocess#api

options.context

Type: Object

more: preprocess#context

options.extension

Type: Object

more: preprocess#options

License

gulp-preprocess-file Based on Preprocess package

MIT © Mervin

Keywords

FAQs

Package last updated on 06 Jun 2018

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