-
Notifications
You must be signed in to change notification settings - Fork 7
/
gulpfile.js
41 lines (38 loc) · 1.15 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict';
const gulp = require('gulp');
const insert = require('gulp-insert');
const rename = require('gulp-rename');
const template = require('gulp-template');
// Compile all *.ejs files to pre-compiled templates and append *.js to the filename.
gulp.task('templates-cjs', () =>
gulp.src('./src/**/*.ejs')
.pipe(template.precompile({
evaluate: /\{%([\s\S]+?)%\}/g,
interpolate: /\{\{([\s\S]+?)\}\}/g,
escape: /\{\{\{([\s\S]+?)\}\}\}/g,
variable: 'ctx'
}))
.pipe(insert.prepend('Object.defineProperty(exports, "__esModule", {\n' +
' value: true\n' +
'});\n' +
'exports.default='))
.pipe(rename({
extname: '.ejs.js'
}))
.pipe(gulp.dest('lib/cjs'))
);
gulp.task('templates-mjs', () =>
gulp.src('./src/**/*.ejs')
.pipe(template.precompile({
evaluate: /\{%([\s\S]+?)%\}/g,
interpolate: /\{\{([\s\S]+?)\}\}/g,
escape: /\{\{\{([\s\S]+?)\}\}\}/g,
variable: 'ctx'
}))
.pipe(insert.prepend('export default '))
.pipe(rename({
extname: '.ejs.js'
}))
.pipe(gulp.dest('lib/mjs'))
);
gulp.task('templates', gulp.parallel(['templates-cjs', 'templates-mjs']));