Skip to content

Commit d2eb420

Browse files
committed
fix: 压缩css, fix #12
2 parents 4515303 + e9560c0 commit d2eb420

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

scripts/lib/rollup.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
**/
55

66
const path = require('path');
7+
const fs = require('fs');
78
const rollup = require('rollup').rollup;
89
const postcss = require('rollup-plugin-postcss');
910
const peerDepsExternal = require('rollup-plugin-peer-deps-external');
@@ -12,6 +13,7 @@ const babel = require('rollup-plugin-babel');
1213
const commonjs = require('rollup-plugin-commonjs');
1314
const {terser} = require('rollup-plugin-terser');
1415
const svgo = require('rollup-plugin-svgo');
16+
const cssnano = require('cssnano');
1517

1618
module.exports = async (dest, src) => {
1719
const inputOptions = {
@@ -34,23 +36,28 @@ module.exports = async (dest, src) => {
3436
})
3537
]
3638
};
37-
39+
3840
const outputMin = {
3941
file: path.join(dest, 'santd.min.js'),
4042
name: 'santd',
4143
exports: 'named',
4244
format: 'umd',
43-
plugins: [terser()]
45+
plugins: [
46+
terser()
47+
]
4448
};
45-
4649
const output = {
4750
file: path.join(dest, 'santd.js'),
4851
name: 'santd',
4952
exports: 'named',
5053
format: 'umd'
5154
};
52-
5355
const bundle = await rollup(inputOptions);
5456
await bundle.write(outputMin);
5557
await bundle.write(output);
58+
59+
// 压缩 https://github.com/egoist/rollup-plugin-postcss/blob/master/src/index.js#L236
60+
let code = fs.readFileSync(path.join(dest, 'santd.css'));
61+
let result = await cssnano.process(code, {from: 'santd.css'});
62+
fs.writeFileSync(path.join(dest, 'santd.min.css'), result.css);
5663
};

0 commit comments

Comments
 (0)