Skip to content

Commit dc303e8

Browse files
committed
Merge pull request #4 from reducejs/refactor
Refactor.
2 parents b5133cb + 72559aa commit dc303e8

File tree

39 files changed

+372
-459
lines changed

39 files changed

+372
-459
lines changed

README.md

Lines changed: 116 additions & 231 deletions
Large diffs are not rendered by default.

example/gulp/multi/gulpfile.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
'use strict'
2+
3+
const reduce = require('reduce-css')
4+
const gulp = require('gulp')
5+
const del = require('del')
6+
const path = require('path')
7+
const build = path.join(__dirname, 'build')
8+
9+
gulp.task('clean', function () {
10+
return del(build)
11+
})
12+
13+
gulp.task('build', ['clean'], function () {
14+
let basedir = path.join(__dirname, 'src')
15+
let b = reduce.create({
16+
basedir,
17+
resolve: {
18+
paths: [path.join(__dirname, 'src', 'web_modules')],
19+
},
20+
})
21+
return reduce.src('page/**/index.css', { cwd: basedir })
22+
.pipe(reduce.bundle(b, {
23+
groups: 'page/**/index.css',
24+
common: 'common.css',
25+
}))
26+
.pipe(reduce.dest(build, null, {
27+
maxSize: 0,
28+
name: '[name].[hash]',
29+
assetOutFolder: path.join(build, 'assets'),
30+
}))
31+
})
32+
33+
gulp.task('watch', ['clean'], function () {
34+
let basedir = path.join(__dirname, 'src')
35+
let b = reduce.create({
36+
basedir,
37+
resolve: {
38+
paths: [path.join(__dirname, 'src', 'web_modules')],
39+
},
40+
})
41+
let count = 1
42+
return gulp.src('page/**/index.css', { cwd: basedir })
43+
.pipe(reduce.watch(b, {
44+
groups: 'page/**/index.css',
45+
common: 'common.css',
46+
}, { entryGlob: 'page/**/index.css' }))
47+
.on('bundle', function (bundleStream) {
48+
bundleStream.pipe(reduce.dest(build, null, {
49+
maxSize: 0,
50+
name: '[name].[hash]',
51+
assetOutFolder: path.join(build, 'assets'),
52+
}))
53+
.on('data', file => console.log('bundle:', file.relative))
54+
.once('end', function () {
55+
console.log('-'.repeat(40), count++ + '')
56+
})
57+
})
58+
})
59+
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@external "reset";
22
@import "helper/color";
3-
a{
3+
.blue {
44
color: $blue;
55
}
66

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
@external "reset";
22
@external "component/button";
33
@import "helper/color";
4+
.red {
5+
color: $red;
6+
}
7+
48
.button {
5-
background-color: $green;
9+
background-color: $red;
610
}
711

example/gulp/reduce/gulpfile.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
'use strict'
2+
3+
const reduce = require('reduce-css')
4+
const gulp = require('gulp')
5+
const del = require('del')
6+
const path = require('path')
7+
const build = path.join(__dirname, 'build')
8+
9+
gulp.task('clean', function () {
10+
return del(build)
11+
})
12+
13+
gulp.task('build', ['clean'], function () {
14+
let basedir = path.join(__dirname, 'src')
15+
let b = reduce.create({
16+
basedir,
17+
resolve: {
18+
paths: [path.join(__dirname, 'src', 'web_modules')],
19+
},
20+
})
21+
return reduce.src('page/**/index.css', { cwd: basedir })
22+
.pipe(reduce.bundle(b, 'bundle.css'))
23+
.pipe(reduce.dest(build, null, {
24+
maxSize: 0,
25+
name: '[name].[hash]',
26+
assetOutFolder: path.join(build, 'assets'),
27+
}))
28+
})
29+
30+
gulp.task('watch', ['clean'], function () {
31+
let basedir = path.join(__dirname, 'src')
32+
let b = reduce.create({
33+
basedir,
34+
resolve: {
35+
paths: [path.join(__dirname, 'src', 'web_modules')],
36+
},
37+
})
38+
let count = 1
39+
return gulp.src('page/**/index.css', { cwd: basedir })
40+
.pipe(reduce.watch(b, 'bundle.css', { entryGlob: 'page/**/index.css' }))
41+
.on('bundle', function (bundleStream) {
42+
bundleStream.pipe(reduce.dest(build, null, {
43+
maxSize: 0,
44+
name: '[name].[hash]',
45+
assetOutFolder: path.join(build, 'assets'),
46+
}))
47+
.on('data', file => console.log('bundle:', file.relative))
48+
.once('end', function () {
49+
console.log('-'.repeat(40), cout++ + '')
50+
if (count > 3) {
51+
b.close()
52+
}
53+
})
54+
})
55+
})
56+

example/multiple-bundles/src/page/blue/index.css renamed to example/gulp/reduce/src/page/blue/index.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@external "component/button";
1+
@external "reset";
22
@import "helper/color";
33
.blue {
44
color: $blue;
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
@external "reset";
12
@external "component/button";
23
@import "helper/color";
34
.red {
45
color: $red;
56
}
67

7-
/* overwrite the default button style */
88
.button {
9-
background-color: $green;
9+
background-color: $red;
1010
}
1111

example/multiple-bundles/gulpfile.js

Lines changed: 0 additions & 80 deletions
This file was deleted.

example/node_modules/reduce-css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/single-bundle/gulpfile.js

Lines changed: 0 additions & 73 deletions
This file was deleted.

example/src/b.css

Lines changed: 0 additions & 7 deletions
This file was deleted.

example/without-gulp/build.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict'
2+
3+
const del = require('del')
4+
const reduce = require('reduce-css')
5+
6+
const build = __dirname + '/build'
7+
const basedir = __dirname + '/src'
8+
const b = reduce.create({ basedir })
9+
del(build).then(function () {
10+
reduce.src('*.css', { cwd: basedir })
11+
.pipe(reduce.bundle(b, 'bundle.css'))
12+
.pipe(reduce.dest(build, null, {
13+
maxSize: 0,
14+
name: '[name].[hash]',
15+
assetOutFolder: build + '/assets',
16+
}))
17+
})
18+

example/without-gulp/multi.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict'
2+
3+
const del = require('del')
4+
const reduce = require('reduce-css')
5+
6+
const build = __dirname + '/build'
7+
const basedir = __dirname + '/src'
8+
const b = reduce.create({ basedir })
9+
b.on('common.map', function (map) {
10+
console.log('bundles:', Object.keys(map).join(', '))
11+
})
12+
del(build).then(function () {
13+
reduce.src('*.css', { cwd: basedir })
14+
.pipe(reduce.bundle(b, {
15+
groups: '*.css',
16+
common: 'common.css',
17+
}))
18+
.pipe(reduce.dest(build, null, {
19+
maxSize: 0,
20+
name: '[name].[hash]',
21+
assetOutFolder: build + '/assets',
22+
}))
23+
})
24+
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
@deps "./reset";
1+
@external "reset";
22
@import "color";
3-
a{
3+
.blue {
44
color: $blue;
55
}
66

example/without-gulp/src/red.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@external "reset";
2+
@external "./button";
3+
@import "color";
4+
.red {
5+
color: $red;
6+
}

0 commit comments

Comments
 (0)