Skip to content

Commit

Permalink
feat: init
Browse files Browse the repository at this point in the history
  • Loading branch information
SoldierAb committed Dec 18, 2019
0 parents commit be18a98
Show file tree
Hide file tree
Showing 12 changed files with 6,050 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
dist/
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

### 1.0.0 (Dec 18, 2019)

- Initial release
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright (C) 2019-2021 gjchen

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Implementation of SCSS skin packaging based on gulp

## Project setup
```
npm install
```

### Compiles and hot-reloads for development
```
npm run dev
```

### Compiles and minifies for production
```
npm run build
```


65 changes: 65 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const gulp = require('gulp'),
scss = require('gulp-sass'),
concat = require('gulp-concat'),
cleanCss = require('gulp-clean-css'),
header = require('gulp-header'),
reanme = require('gulp-rename'),
sourcemaps = require('gulp-sourcemaps'),
autoprefix = require('gulp-autoprefixer'),
fs = require("fs"),
del = require('del'),
theme = process.env.npm_config_theme || 'default',
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(autoprefix())
.pipe(reanme((path) => {
return {
dirname: path.dirname,
basename: path.basename,
suffix: '.min',
extname: ".css"
}
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(`${output_path}/style/modules/`))
.pipe(concat(`${theme}.min.css`))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(`${output_path}/style/`))
}

// scss 全局变量注入
const setGlobalScss = () => {
const resDefault = fs.readFileSync(`./src/theme/${theme}.scss`),
resCommon = fs.readFileSync('./src/theme/common.scss'),
scssString = resCommon.toString() + " \n " + resDefault.toString();
return header(scssString);
}

const watchPipe = () => {
const watcher = gulp.watch(scss_path);
watcher.on("change", gulp.series('clean', 'scss'))
watcher.on("add", gulp.series('clean', 'scss'))
watcher.on("unlink", gulp.series('clean', 'scss'))
// watcher.on('unlink', function (path, stats) {
// console.log(`File ${path} was removed,${stats}`);
// scssTask()
// });
}

const cleanFiles = () => {
return del(output_path, { read: false })
}

gulp.task('clean', cleanFiles)
gulp.task('watch', watchPipe)
gulp.task('scss', scssTask)

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

0 comments on commit be18a98

Please sign in to comment.