Skip to content

Commit

Permalink
Config rule per extension (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartijnCuppens committed Feb 19, 2020
1 parent 88ab441 commit d207faa
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 23 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,22 @@ Buildozer uses a `.buildozerrc` configuration file which uses the yaml syntax an
src_base_path: ./
dest_base_path: ./
scss:
- src: scss/**/*.css
dest: dest/css
- src: scss/**/*.scss
dest: dest/css
- src: scss/**/*.sass
dest: dest/css
img:
- src: img/**/*.{png,jpg,jpeg,gif,svg}
- src: img/**/*.png
dest: dest/img
- src: img/**/*.jpg
dest: dest/img
- src: img/**/*.jpeg
dest: dest/img
- src: img/**/*.gif
dest: dest/img
- src: img/**/*.svg
dest: dest/img
js:
- src: js/**/*.js
Expand Down
14 changes: 13 additions & 1 deletion lib/.buildozerrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
src_base_path: ./
dest_base_path: ./
scss:
- src: scss/**/*.css
dest: dest/css
- src: scss/**/*.scss
dest: dest/css
- src: scss/**/*.sass
dest: dest/css
img:
- src: img/**/*.{png,jpg,jpeg,gif,svg}
- src: img/**/*.png
dest: dest/img
- src: img/**/*.jpg
dest: dest/img
- src: img/**/*.jpeg
dest: dest/img
- src: img/**/*.gif
dest: dest/img
- src: img/**/*.svg
dest: dest/img
js:
- src: js/**/*.js
Expand Down
26 changes: 16 additions & 10 deletions lib/gulp/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,22 @@ function cssCompile({src, dest, cwd, browserSync = false}) {
.pipe(gulpIf(file => process.argv.includes('--fix') && file._contents.toString('utf8') !== file.original, gulp.dest(file => file._base))); // Update fixed version differs
}

if (process.env.NODE_ENV === 'production') {
stream = stream
.pipe(sass({outputStyle: 'compressed', fiber}))
.pipe(postcss(plugins, options));
} else {
stream = stream
.pipe(sourcemaps.init())
.pipe(sass({outputStyle: 'expanded'}))
.pipe(postcss(plugins, options))
.pipe(sourcemaps.write('.'));
// Init sourcemaps
if (process.env.NODE_ENV !== 'production') {
stream = stream.pipe(sourcemaps.init());
}

// We better check for .scss and .sass extentions, but use this for backwards compatibility with <= v0.3.1
if (!src.endsWith('.css')) {
stream = stream.pipe(sass({outputStyle: 'expanded', fiber}));
}

// Apply PostCSS plugins
stream = stream.pipe(postcss(plugins, options));

// Write sourcemaps
if (process.env.NODE_ENV !== 'production') {
stream = stream.pipe(sourcemaps.write('.'));
}

stream = stream.pipe(gulp.dest(dest));
Expand Down
45 changes: 35 additions & 10 deletions lib/gulp/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,54 @@ function imgCompile({src, dest, browserSync = false}) {
stream = stream.pipe(plumber());
}

stream = stream.pipe(newer(dest))
.pipe(
imagemin([
imagemin.gifsicle({interlaced: true}),
imagemin.mozjpeg({progressive: true}),
imagemin.optipng({optimizationLevel: 5}),
imagemin.svgo({
const extension = src.split('.').pop();

const plugins = (() => {
switch (extension) {
case 'gif':
return imagemin.gifsicle({interlaced: true});
case 'png':
return imagemin.optipng({optimizationLevel: 5});
case 'svg':
return imagemin.svgo({
plugins: [
{
removeViewBox: false,
collapseGroups: true
}
]
})
], {
});
case 'jpg':
case 'jpeg':
return imagemin.mozjpeg({progressive: true});
default: // Required for backwards compatibility with <= v0.3.1
return [
imagemin.gifsicle({interlaced: true}),
imagemin.mozjpeg({progressive: true}),
imagemin.optipng({optimizationLevel: 5}),
imagemin.svgo({
plugins: [
{
removeViewBox: false,
collapseGroups: true
}
]
})
];
}
})();

stream = stream.pipe(newer(dest))
.pipe(
imagemin([plugins], {
silent: true
})
);

stream = stream.pipe(gulp.dest(dest));

if (browserSync !== false) {
stream = stream.pipe(browserSync.stream({match: '**/*.{png,jpg,jpeg,gif,svg}'}));
stream = stream.pipe(browserSync.stream({match: `**/*.${extension}`}));
}

stream.on('end', resolve);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"unit-tests": "npm-run-all test-* --parallel",
"lint": "xo",
"test-default": "cd test/default && node ../../bin/buildozer build",
"test-css": "cd test/css && node ../../bin/buildozer build",
"test-env": "cd test/env && node ../../bin/buildozer build --env=development",
"test-copy": "cd test/copy && node ../../bin/buildozer build",
"test-sass-module": "cd test/sass-module && node ../../bin/buildozer build",
Expand Down
6 changes: 5 additions & 1 deletion test/config-search/nested/dest/css/main.css
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
body{background:red;appearance:none;font-size:1.25rem}
body {
background: red;
appearance: none;
font-size: 1.25rem;
}
12 changes: 12 additions & 0 deletions test/css/.buildozerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
src_base_path: ./
dest_base_path: ./
img: []
js: []
js-concat: []
svg-sprite: []
browsersync:
server: null # Static sites
proxy: null # Dynamic sites
reload: null # Glob to watch for reload
config_search:
enabled: false
1 change: 1 addition & 0 deletions test/css/dest/css/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select{-webkit-appearance:none;-moz-appearance:none;appearance:none}
4 changes: 4 additions & 0 deletions test/css/scss/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
select {
/* Comment */
appearance: none;
}

0 comments on commit d207faa

Please # to comment.