在临时文件夹中注入文件时,自动附加src文件夹

时间:2019-10-29 08:18:04

标签: gulp-4

我目前正在将gulp 3.x迁移到gulp 4.x, 在这个gulp html文件中创建一个临时文件夹。在此文件中会自动添加src /文件夹。

预期结果 .tmp / serve

内部服务以下文件结构需要存在。 app / index.css index.html

实际结果 1.serve / app / src / app / index.css 2.serve / src / index.html

在此src文件夹中需要删除。 我将与此一起附加整个gulp build.js文件。

<trace source="MyApi" severity="information">
    <message>@(context.Request.Headers.GetValueOrDefault("Authorization","No auth header").AsJwt()?.Claims.GetValueOrDefault("name", "No name field"))</message>
</trace>

});

  (function () {
      'use strict';

        var path = require('path');
        var gulp = require('gulp');
        var conf = require('./conf');
        var inject = require('./inject');

       var $ = require('gulp-load-plugins')({
pattern: ['gulp-*', 'npmfiles', 'uglify-save-license', 'del']

}));

      function partials(){
          return gulp.src([
          path.join(conf.paths.src, '/app/**/*.html'),
         path.join(conf.paths.tmp, '/serve/app/**/*.html')
    ])
  .pipe($.htmlmin({
    removeEmptyAttributes: true,
    removeAttributeQuotes: true,
    collapseBooleanAttributes: true,
    collapseWhitespace: true
  }))
  .pipe($.angularTemplatecache('templateCacheHtml.js', {
    module: 'hubble',
    root: 'app'
  }))
  .pipe(gulp.dest(conf.paths.tmp + '/partials/'));
    };
     gulp.task('partials', gulp.series(partials));


     gulp.task('html', gulp.series('inject', 'partials', function html () 
    {
       var partialsInjectFile = gulp.src(path.join(conf.paths.tmp, 
       '/partials/templateCacheHtml.js'), { read: false });
       var partialsInjectOptions = {
        starttag: '<!-- inject:partials -->',
        ignorePath: path.join(conf.paths.tmp, '/partials'),
        addRootSlash: false
    };

var htmlFilter = $.filter('*.html', { restore: true, dot: true, matchBase: true });
var jsFilter = $.filter('**/*.js', { restore: true , dot: true});
var cssFilter = $.filter('**/*.css', { restore: true , dot: true});

return gulp.src(path.join(conf.paths.tmp, '/serve/*.html'))
  .pipe($.inject(partialsInjectFile, partialsInjectOptions))
  .pipe($.useref())
  .pipe(jsFilter)
  .pipe($.rev())
  .pipe($.sourcemaps.init())
  .pipe($.ngAnnotate())
  .pipe($.uglify()).on('error', conf.errorHandler('Uglify'))
  //.pipe($.sourcemaps.write('maps'))
  .pipe(jsFilter.restore)
  .pipe(cssFilter)
  // .pipe($.sourcemaps.init())
  .pipe($.replace('Casino_Hand/', '../fonts/'))
  .pipe($.cssnano({
    zindex: false
  }))
  .pipe($.rev())
  // .pipe($.sourcemaps.write('maps'))
  .pipe(cssFilter.restore)
  .pipe($.revReplace())
  .pipe(htmlFilter)
  .pipe($.htmlmin({
    removeEmptyAttributes: true,
    removeAttributeQuotes: false,
    collapseBooleanAttributes: true,
    collapseWhitespace: true
  }))
  .pipe(htmlFilter.restore)
  .pipe(gulp.dest(path.join(conf.paths.dist, '/')))
  .pipe($.size({ title: path.join(conf.paths.dist, '/'), showFiles: true }));

};

  function other(){
var fileFilter = $.filter(function (file) {
  return file.stat.isFile();
});0

return gulp.src([
  path.join(conf.paths.src, '/**/*'),
  path.join('!' + conf.paths.src, '/**/*.{html,css,js,scss}')
])
.pipe(fileFilter)
.pipe(gulp.dest(path.join(conf.paths.dist, '/')));

//仍然注入GlobalConfig.js(但不要最小化)以允许部署工具在需要时更新现有值

     function clean(){
return $.del([path.join(conf.paths.dist, '/'), path.join(conf.paths.tmp, 
   '/')]);
  };
     gulp.task('clean',gulp.series(clean));

1 个答案:

答案 0 :(得分:0)

不要使用path.join提供src的路径,一切都会好的。 例如,代替:

gulp.src([
    path.join(conf.paths.src, '/**/*'),
    path.join('!' + conf.paths.src, '/**/*.{html,css,js,scss}')
])

使用:

gulp.src([
    conf.paths.src + '/**/*',
    '!' + conf.paths.src + '/**/*.{html,css,js,scss}'
])