Skip to content

Commit 50cc200

Browse files
committed
feat(pack): add -m/--min option
1 parent 51d5dda commit 50cc200

File tree

8 files changed

+49
-4
lines changed

8 files changed

+49
-4
lines changed

examples/pack-min/dist/bundle.js

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

examples/pack-min/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<html>
2+
3+
<head>
4+
<meta charset="utf-8">
5+
<title>YKit Pack-CommonJs Test</title>
6+
</head>
7+
8+
<body>
9+
<h1 id="ykit">YKit Pack-CommonJs Test</h1>
10+
<script src="./dist/bundle.js"></script>
11+
</body>
12+
13+
</html>

examples/pack-min/src/entry.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var m1Log = require('./module1')
2+
var m2Log = require('./module2')
3+
4+
document.write("<h2>require following modules:</h2>")
5+
m1Log()
6+
m2Log()

examples/pack-min/src/module1.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = function () {
2+
document.write("<h3>module 1</h3>")
3+
}

examples/pack-min/src/module2.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = function () {
2+
document.write("<h3>module 2</h3>")
3+
}

examples/pack-min/ykit.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

src/commands/pack.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ var webpack = require('webpack')
33
exports.usage = "资源编译、打包";
44

55
exports.setOptions = (optimist) => {
6-
// TODO
6+
optimist.alias('m', 'min');
7+
optimist.describe('m', '压缩/混淆项目文件');
78
};
89

910
exports.run = function(options) {
@@ -20,12 +21,19 @@ exports.run = function(options) {
2021
loaders: [{
2122
test: /\.js$/,
2223
exclude: /(node_modules|bower_components)/,
23-
loader: 'babel', // 'babel-loader' is also a legal name to reference
24+
loader: 'babel',
2425
query: {
2526
presets: ['es2015']
2627
}
2728
}]
28-
}
29+
},
30+
plugins: [
31+
options.m ? new webpack.optimize.UglifyJsPlugin({
32+
compress: {
33+
warnings: false
34+
}
35+
}) : null
36+
],
2937
}, function(err, stats) {
3038
if (err) {
3139
info(err);

test/pack.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ describe('pack command', function() {
66
this.timeout(8000);
77

88
afterEach(function() {
9-
// runs before all tests in this block
109
cd('../../')
1110
})
1211

@@ -42,4 +41,15 @@ describe('pack command', function() {
4241
assert.equal(result.code, 0);
4342
});
4443
});
44+
45+
describe('min', function() {
46+
it('command code should return 0', function() {
47+
cd('./examples/pack-min')
48+
49+
var result = exec('node ../../bin/ykit pack -m', {
50+
silent: true
51+
});
52+
assert.equal(result.code, 0);
53+
});
54+
});
4555
});

0 commit comments

Comments
 (0)