使用Gulp,是否可以将环境变量作为注释添加到CSS中? (例如package.json版本) [英] Using Gulp, is it possible to add environment variables as a comment into CSS? (for example the package.json version)

查看:93
本文介绍了使用Gulp,是否可以将环境变量作为注释添加到CSS中? (例如package.json版本)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用gulp设置在SCSS文件中传递特定的环境变量?

Is it possible to pipe through specific environment variables in an SCSS file using a gulp setup?

例如,您可以使用类似的东西吗?

Could you, for example, use something like:

/*! %version% */

版本将是package.json中使用的版本号.

Where version would be the version number as used in package.json.

推荐答案

来自 gulp-header 示例:

// using data from package.json

var pkg = require('./package.json');

//var banner = ['/**',
//  ' * <%= pkg.name %> - <%= pkg.description %>',
//  ' * @version v<%= pkg.version %>',
//  ' * @link <%= pkg.homepage %>',
//  ' * @license <%= pkg.license %>',
//  ' */',
//  ''].join('\n');

// in your case all you need is:
var banner = ['/*! <%= pkg.version %> */\n'];

// in your task 
gulp.src('./foo/*.scss')
  .pipe(header(banner, { pkg : pkg } ))
  .pipe(sourcemaps.init())
  // if you are using sourcemaps, init them after injecting the header commment

  .pipe(sass().on("error", sass.logError))
  .pipe(sourcemaps.write("sourcemaps"))
  .pipe(gulp.dest('./dist/'))

这篇关于使用Gulp,是否可以将环境变量作为注释添加到CSS中? (例如package.json版本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆