Skip to content

Commit 4615fd0

Browse files
committed
feat(pack): add pack command demo & test
1 parent e0c26fd commit 4615fd0

File tree

8 files changed

+129
-1
lines changed

8 files changed

+129
-1
lines changed

examples/pack/dist/bundle.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/******/ (function(modules) { // webpackBootstrap
2+
/******/ // The module cache
3+
/******/ var installedModules = {};
4+
5+
/******/ // The require function
6+
/******/ function __webpack_require__(moduleId) {
7+
8+
/******/ // Check if module is in cache
9+
/******/ if(installedModules[moduleId])
10+
/******/ return installedModules[moduleId].exports;
11+
12+
/******/ // Create a new module (and put it into the cache)
13+
/******/ var module = installedModules[moduleId] = {
14+
/******/ exports: {},
15+
/******/ id: moduleId,
16+
/******/ loaded: false
17+
/******/ };
18+
19+
/******/ // Execute the module function
20+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
21+
22+
/******/ // Flag the module as loaded
23+
/******/ module.loaded = true;
24+
25+
/******/ // Return the exports of the module
26+
/******/ return module.exports;
27+
/******/ }
28+
29+
30+
/******/ // expose the modules object (__webpack_modules__)
31+
/******/ __webpack_require__.m = modules;
32+
33+
/******/ // expose the module cache
34+
/******/ __webpack_require__.c = installedModules;
35+
36+
/******/ // __webpack_public_path__
37+
/******/ __webpack_require__.p = "";
38+
39+
/******/ // Load entry module and return exports
40+
/******/ return __webpack_require__(0);
41+
/******/ })
42+
/************************************************************************/
43+
/******/ ([
44+
/* 0 */
45+
/***/ function(module, exports, __webpack_require__) {
46+
47+
__webpack_require__(1)
48+
__webpack_require__(2)
49+
50+
51+
/***/ },
52+
/* 1 */
53+
/***/ function(module, exports) {
54+
55+
module.exports = function () {
56+
console.log('module1');
57+
}
58+
59+
60+
/***/ },
61+
/* 2 */
62+
/***/ function(module, exports) {
63+
64+
module.exports = function () {
65+
console.log('module2');
66+
}
67+
68+
69+
/***/ }
70+
/******/ ]);

examples/pack/src/entry.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require('./module1')
2+
require('./module2')

examples/pack/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+
console.log('module1');
3+
}

examples/pack/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+
console.log('module2');
3+
}

examples/pack/ykit.config

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

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,16 @@
1515
"globby": "^5.0.0",
1616
"left-pad": "^1.1.0",
1717
"optimist": "^0.6.1",
18-
"right-pad": "^1.0.0"
18+
"right-pad": "^1.0.0",
19+
"webpack": "^1.13.1"
1920
},
2021
"repository": {
2122
"type": "git",
2223
"url": "git@gitlab.corp.qunar.com:mfe/ykit.git"
24+
},
25+
"devDependencies": {
26+
"chai": "^3.5.0",
27+
"mocha": "^2.5.3",
28+
"shelljs": "^0.7.0"
2329
}
2430
}

src/commands/pack.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
var webpack = require('webpack')
2+
3+
exports.usage = "资源编译、打包";
4+
5+
exports.setOptions = (optimist) => {
6+
// TODO
7+
};
8+
9+
exports.run = function(options) {
10+
var cmdExecutedPath = process.cwd()
11+
12+
webpack({
13+
context: cmdExecutedPath,
14+
entry: "./src/entry.js",
15+
output: {
16+
path: "./dist",
17+
filename: "bundle.js"
18+
}
19+
}, function(err, stats) {
20+
if(err){
21+
info(err);
22+
return
23+
}
24+
25+
info('pack succeed');
26+
})
27+
};

test/pack.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
require('shelljs/global')
2+
3+
var assert = require('chai').assert;
4+
5+
describe('command', function() {
6+
describe('pack', function() {
7+
it('pack command should return 0', function() {
8+
this.timeout(5000);
9+
10+
cd('./examples/pack/')
11+
12+
var result = exec('node ../../bin/ykit pack', {silent:true});
13+
assert.equal(result.code, 0);
14+
});
15+
});
16+
});

0 commit comments

Comments
 (0)