Skip to content

Commit

Permalink
feat: sourcemap
Browse files Browse the repository at this point in the history
  • Loading branch information
SoldierAb committed Dec 19, 2019
1 parent be18a98 commit 99452ce
Show file tree
Hide file tree
Showing 3 changed files with 505 additions and 54 deletions.
20 changes: 12 additions & 8 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,39 @@ const gulp = require('gulp'),
concat = require('gulp-concat'),
cleanCss = require('gulp-clean-css'),
header = require('gulp-header'),
reanme = require('gulp-rename'),
rename = require('gulp-rename'),
sourcemaps = require('gulp-sourcemaps'),
autoprefix = require('gulp-autoprefixer'),
gulpif = require('gulp-if'),
fs = require("fs"),
del = require('del'),
theme = process.env.npm_config_theme || 'default',
argv = require('yargs').argv,
node_env = argv.env || 'development',
scss_path = ['src/**/*.scss', '!node_modules'],
output_path = 'dist/';


const scssTask = () => {
gulp.src([...scss_path, '!src/theme/*.scss'])
.pipe(sourcemaps.init())
.on('error', scss.logError)//错误信息
.pipe(setGlobalScss())
.pipe(scss())
.pipe(cleanCss())
.pipe(gulpif(node_env === 'production', cleanCss())) // 仅在生产环境时候进行压缩
.pipe(autoprefix())
.pipe(reanme((path) => {
return {
.pipe(rename((path) => {
return{
dirname: path.dirname,
basename: path.basename,
suffix: '.min',
extname: ".css"
}
}))
.pipe(sourcemaps.write('.'))
// .pipe(sourcemaps.write('./'))
.pipe(gulp.dest(`${output_path}/style/modules/`))
.pipe(concat(`${theme}.min.css`))
.pipe(sourcemaps.write('.'))
.pipe(concat(`${theme}${node_env === 'production'?'.min':''}.css`))
// .pipe(sourcemaps.write('./'))
.pipe(gulp.dest(`${output_path}/style/`))
}

Expand Down Expand Up @@ -62,4 +66,4 @@ gulp.task('clean', cleanFiles)
gulp.task('watch', watchPipe)
gulp.task('scss', scssTask)

gulp.task('default', gulp.series('clean', gulp.parallel('scss', 'watch')))
gulp.task('default', gulp.series('clean', gulp.parallel('scss', 'watch')))
Loading

0 comments on commit 99452ce

Please sign in to comment.