gulp-preprocess-file

2.1.0 • Public • Published

gulp-preprocess-file

A Gulp plugin for Preprocess

Preprocess HTML, JavaScript, and other files with directives based off custom or ENV configuration

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({
      NODE_ENV: 'production',
      title: 'this is a title',
      cdnFile: function(file) {
        return 'https://cdn.com/' + file
      }
    }, {
      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({
      NODE_ENV: 'production',
      name: 'John'
    }, {
      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(context, options)

context

Type: Object

more: preprocess#context

options

Type: Object

more: preprocess#options

API

preprocess#api

License

gulp-preprocess-file Based on Preprocess package

MIT © Mervin

Package Sidebar

Install

npm i gulp-preprocess-file

Weekly Downloads

2

Version

2.1.0

License

MIT

Unpacked Size

4.61 kB

Total Files

4

Last publish

Collaborators

  • mengqing723