问题
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% */
Where version would be the version number as used in package.json.
回答1:
From gulp-header example:
// 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/'))
来源:https://stackoverflow.com/questions/51722816/using-gulp-is-it-possible-to-add-environment-variables-as-a-comment-into-css