gulp-texttojs

2019-07-14 admin

gulp-texttojs是什么

什么是gulp-texttojs,Compiles text files into javascript files.

gulp-texttojs使用教程帮助文档

gulp-texttojs

Converts text files into JavaScript.

Install

Install with npm

$ npm install --save-dev gulp-texttojs

Description

Converts a text file (css, html, etc) into a javascript file, which by default is exported as an amd module, but can be tweaked to do anything you want with the file as a javascript string.

Usage

var gulp = require('gulp'),
    texttojs = require('gulp-texttojs');

gulp.task('default', function() {
    return gulp.src('src/*.css')
        .pipe(texttojs()
        .pipe(gulp.dest('dist'));
});

Input (file.txt):

Hello, "world!"

Output (file.txt.js):

define([], function() { return "Hello, \"world!\""; });

API

texttojs(options)

options.template

Type: String or Function Default: define([], function() { return <%= content %>; });

You can use <%= content %> to place the text file string content. The content will include quotes around the escaped content. By default the file is converted into an AMD export. The function will be passed the current stream file object and is expected to return the template string.

options.ext

Type: ‘String’ Default: .js

options.isExtensionAppended

Type: ‘Boolean’ Default: true

If set to true, the extension is appended to the filename. Otherwise the current extension is replaced with the given ext value if provided.

License

MIT © David Zearing

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-69737.html

文章标题:gulp-texttojs

回到顶部