Привет, я новичок в Gulp, и мое требование - исключить определенные js-файлы из записи в index.html в задаче build-dist.Ниже приведены файлы, которые нужно исключить из записи в index.html.
Ниже приведен файл gulpfile.js: для моего требования я предполагаю, что gulp.task ('full-build-dist', ['build-dist'] следует изменить, чтобы указать указанные js-файлы с префиксом (!), но не знаю действительный код, поэтому ваша помощь будет оценена.
'use strict';
/*** DO NOT MODIFY THIS FILE ***/
let gulp = require('gulp');
let fs = require('fs-extra');
let inject = require('gulp-inject');
let sequence = require('run-sequence');
/**
* Load the default configuration from the ng1-template-gulp package.
*/
let ng1TemplateGulp = require('ng1-template-gulp');
let config = ng1TemplateGulp.config;
let utils = ng1TemplateGulp.utils;
/**
* Once the config is loaded from the ng1-template-gulp package, call the local gulp.config module
* to customize the config as per the project requirements.
*/
utils.compileTsFile('./gulp.config.ts', config.folders.build);
require(`${config.folders.build}gulp.config`)(config);
config.options.bowerJson = require(`${config.folders.root}bower.json`);
gulp.task('load_rev_manifest', done => {
config.revManifest = require(`${config.folders.distBuild}rev-manifest.json`);
done();
});
gulp.task('full-build-dist', ['build-dist'], () => {
utils.log('Creating a new json file for cms to use');
var fileContent = fs.readFileSync(`${config.folders.distBuild}index.html`, "utf8");
let array = fileContent.split('<script');
let result = [];
for (let i = 0; i < array.length; i++) {
if (i == 0 || i == array.length - 1 || i == array.length - 2) {
continue;
}
let elem = array[i];
let tempResult = elem.substring(elem.indexOf('js/') + 3, elem.indexOf('</script>') - 2);
result.push(tempResult);
}
utils.log(`Element :${config.folders.distBuild}` + JSON.stringify(result));
fs.writeJson(`${config.folders.distBuild}library.json`, result, function (err) {
// console.log(err)
})
});
var bless = require('gulp-bless');
gulp.task('split', () => {
utils.log('css only' + `${config.folders.distBuild}css`);
return gulp.src(`${config.folders.distBuild}css/*.css`)
.pipe(bless({
imports: false,
suffix: '-part'
}))
.pipe(gulp.dest(`${config.folders.distBuild}css`));
});
gulp.task('complete-build', function () {
sequence('clean', 'build-dist', 'copy-files-upload', 'copy-files-upload1', 'copy-files-upload2', 'copy-files-upload3', 'copy-files-add', 'split', 'add-css');
});
gulp.task('add-css', function () {
let cssFiles = `${config.folders.distBuild}css/*part1.css`;
let cssSrc = gulp.src(cssFiles, { read: false });
let configOptions = {
starttag: '<!-- inject:css:def -->',
relative: true,
removeTags: true
};
let injectTask = utils.src(`${config.folders.distBuild}index.html`, 'local-inject')
.pipe(inject(cssSrc, configOptions));
injectTask = injectTask.pipe(gulp.dest(`${config.folders.distBuild}`));
return injectTask;
});
gulp.task('copy-files-upload', function () {
let jsFiles = [`${config.folders.bower}ng-file-upload-shim/*`];
return gulp.src(jsFiles).pipe(gulp.dest(`${config.folders.distBuild}js/ng-file-upload-shim`));
});
gulp.task('copy-files-upload1', function () {
let jsFiles1 = [`${config.folders.bower}ng-file-upload/*`];
return gulp.src(jsFiles1).pipe(gulp.dest(`${config.folders.distBuild}js/ng-file-upload`));
});
gulp.task('copy-files-upload2', function () {
let jsFiles2 = [`${config.folders.client}/customjs/fileuploader.js`];
return gulp.src(jsFiles2).pipe(gulp.dest(`${config.folders.distBuild}js`));
});
gulp.task('copy-files-upload3', function () {
let jsFiles2 = [`${config.folders.client}/customjs/tealeaf*.js`];
console.log('jsFiles2', jsFiles2);
return gulp.src(jsFiles2).pipe(gulp.dest(`${config.folders.distBuild}js`));
});
gulp.task('copy-files-add', function () {
let jsFiles = [`${config.folders.distBuild}js/ng-file-upload/ng-file-upload-shim.js`, `${config.folders.distBuild}js/ng-file-upload/ng-file-upload.js`, `${config.folders.distBuild}js/fileuploader.js`, `${config.folders.distBuild}js/tealeaf*.js`];
let jsSrc = gulp.src(jsFiles, { read: false });
let configOptions = {
starttag: '<!-- inject:js:upload -->',
relative: true,
removeTags: true
};
let injectTask = utils.src(`${config.folders.distBuild}index.html`, 'local-inject')
.pipe(inject(jsSrc, configOptions));
injectTask = injectTask.pipe(gulp.dest(`${config.folders.distBuild}`));
return injectTask;
});