gulp.spritesmith的等效webpack spritesmith配置是什么?

我在gulp任务管道中有以下任务:

var config      = require('../build-config')
var gulp        = require('gulp')
var spritesmith = require('gulp.spritesmith')
var path        = require('path')
var merge       = require('merge-stream');

var paths = {
  // image source location
  src: path.join(config.root.src,config.tasks.images.src,'**/*.{' + config.tasks.images.extensions.join(',') + '}'),// final destination file location
  dest: path.join(config.root.dest,config.tasks.images.dest),// describe how to make the file
  handlebarsTemplateSrc: path.join(config.root.src,'handlebarsStr.css.handlebars'),// all the styles files
  styleDest: path.join(config.root.src,config.tasks.images.generatedStyleDest),}

  // for task 'images'
  gulp.task('images',function() {
  console.log(paths);
  var spriteData = gulp.src(paths.src).pipe(spritesmith({
    // final destination file name
    imgName: 'sprite.png',// use this as style for every input file
    cssname: 'sprites.less',// describe how to make the file
    cssTemplate: paths.handlebarsTemplateSrc
  }));

  var imgStream = spriteData.img.pipe(gulp.dest(paths.dest));
  var cssStream = spriteData.css.pipe(gulp.dest(paths.styleDest));
  //return merge(imgStream,cssStream).pipe(browserSync.reload({stream:true}));
  // console.log(imgStream);
  return merge(imgStream,cssStream);
})

我想使用webpack-spritesmith npm软件包将其转换为等效的webpack配置,以摆脱掉一团糟。我已经尝试了一些配置,但是由于不了解发生了什么,最终我陷入了混乱。如果可以的话,请帮忙。

谢谢。

s13766553829 回答:gulp.spritesmith的等效webpack spritesmith配置是什么?

让它终于在一天后开始工作...

安装并导入以下软件包

var SpritesmithPlugin = require('webpack-spritesmith');

webpack配置文件中的内部插件>>

new SpritesmithPlugin({
            src: {
                cwd: imagesPath,// path to folder containing images
                glob: '**/*.{jpg,png}' // glob pattern (used to search files with extension similar to regex)
            },target: {
                // output spritesheet location name combined with filename
                image: path.resolve(__dirname,"..",'dist/images/')+'/sprite.png',// output coordinate map location name combined with filename
                css: [ [path.resolve(__dirname,'dist/images/') + '/sprites.less',{format:'handlebars_based_template'}]],},apiOptions: {
                cssImageRef: "~sprite.png",customTemplates: {
                //these are handle bars used to create custom spritesheet
                'handlebars_based_template': path.resolve(__dirname,"src/app/images/") + "/handlebarsStr.css.handlebars",}

        }),

谢谢我。

本文链接:https://www.f2er.com/3123790.html

大家都在问