Skip to content

Commit

Permalink
[ Optimize ] Reduce the Bundle size
Browse files Browse the repository at this point in the history
[ Optimize ]  Update Upstream packages
  • Loading branch information
TechQuery committed Feb 23, 2019
1 parent 82dca1d commit 01d8318
Show file tree
Hide file tree
Showing 10 changed files with 2,554 additions and 1,795 deletions.
1 change: 1 addition & 0 deletions .esdoc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"index": "ReadMe.md",
"source": "./source",
"destination": "./docs",
"plugins": [
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,6 @@ typings/
.vscode/
.idea/

# Runtime
# Release building
build/
docs/
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.editorconfig
.eslintrc.json
test/
.esdoc.json
docs/
test/
.travis.yml
8 changes: 0 additions & 8 deletions install.js

This file was deleted.

4,159 changes: 2,455 additions & 1,704 deletions package-lock.json

Large diffs are not rendered by default.

52 changes: 29 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "amd-bundle",
"version": "1.7.4",
"version": "1.7.5",
"description": "A dual-use tool for bundling up AMD modules, which is much easier to use than r.js with Almond or AMDclean",
"keywords": [
"javascript",
Expand All @@ -11,7 +11,7 @@
],
"author": "[email protected]",
"license": "AGPL-3.0",
"homepage": "https://techquery.github.io/AMD_bundle.js/",
"homepage": "https://tech-query.me/AMD_bundle.js/",
"repository": {
"type": "git",
"url": "git+https://github.com/TechQuery/AMD_bundle.js.git"
Expand All @@ -22,51 +22,57 @@
"main": "build/Package.js",
"bin": "build/index.js",
"engines": {
"node": "^6.5.0"
"node": "^6.3.0"
},
"scripts": {
"lint": "eslint install.js source/ test/*.js --fix",
"bundle": "babel source/ --out-dir build/",
"check": "mocha -r @babel/register -r @babel/polyfill -r should -c --inline-diffs",
"test": "npm run check -- --exit",
"debug": "npm run check -- --inspect-brk",
"lint": "eslint source/ test/*.js --fix",
"bundle": "babel source/ -d build/ -s",
"test": "mocha --exit",
"debug": "mocha --inspect-brk",
"build": "npm run lint && npm run bundle && npm test && esdoc",
"prepublishOnly": "npm run build",
"start": "web-server docs/ -o",
"install": "node install"
"install": "node -e \"console.log('exports.test = 1;')\" > node_modules/test.js"
},
"husky": {
"hooks": {
"pre-commit": "npm run build && git add ."
}
},
"dependencies": {
"@babel/core": "^7.1.2",
"@babel/plugin-transform-modules-commonjs": "^7.1.0",
"@babel/polyfill": "^7.0.0",
"@babel/preset-env": "^7.1.0",
"@babel/core": "^7.3.3",
"@babel/plugin-transform-modules-commonjs": "^7.2.0",
"@babel/polyfill": "^7.2.5",
"@babel/preset-env": "^7.3.1",
"@babel/register": "^7.0.0",
"@babel/runtime": "^7.1.2",
"@tech_query/node-toolkit": "^0.7.1",
"@babel/runtime": "^7.3.1",
"@tech_query/node-toolkit": "^0.9.1",
"commander": "^2.19.0",
"fs-extra": "^7.0.0"
"fs-extra": "^7.0.1"
},
"devDependencies": {
"@babel/cli": "^7.1.2",
"@babel/plugin-transform-runtime": "^7.1.0",
"@babel/cli": "^7.2.3",
"@babel/plugin-transform-runtime": "^7.2.0",
"cross-env": "^5.2.0",
"esdoc": "^1.1.0",
"esdoc-external-nodejs-plugin": "^1.0.0",
"esdoc-standard-plugin": "^1.0.0",
"eslint": "^5.8.0",
"husky": "^1.1.2",
"koapache": "^1.0.4",
"mocha": "^5.2.0",
"eslint": "^5.14.1",
"husky": "^1.3.1",
"koapache": "^1.0.5",
"mocha": "^6.0.1",
"should": "^13.2.3"
},
"babel": {
"presets": [
"@babel/preset-env"
[
"@babel/preset-env",
{
"targets": {
"node": "6.3.0"
}
}
]
],
"plugins": [
"@babel/plugin-transform-runtime"
Expand Down
22 changes: 12 additions & 10 deletions source/UMD.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ import { merge, outPackage } from './utility';
function concatModule(pack, name, modName, varName) { /* eslint-disable */

return toES_5(`
var _module_ = {
var _module_ = { };
${
Array.from(pack, item => `
'${item.name}': {
base: '${item.base}',
dependency: ${JSON.stringify( Object.keys( item.dependency.compile ) )},
factory: ${item.source}
}`.slice(1)
_module_['${item.name}'] = {
base: '${item.base}',
dependency: ${JSON.stringify( Object.keys( item.dependency.compile ) )}
};
_module_['${item.name}'].factory = ${item.source}`
).concat(
modName.map((name, index) => `'${name}': {exports: ${varName[index]}}`)
).join(',\n')}
};
`,
modName.map((name, index) =>
`_module_['${name}'] = {exports: ${varName[index]}};`
)
).join(',\n')
}`,
name
);
}
Expand Down
93 changes: 46 additions & 47 deletions test/example/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,58 +68,57 @@ function outPackage(name) {
return module.exports;
}

var _module_ = {
'./c': {
base: '.',
dependency: [],
factory: function factory(require, exports, module) {
require('./libs/b');
var _module_ = {};
_module_['./c'] = {
base: '.',
dependency: []
};
(_module_['./c'].factory = function(require, exports, module) {
require('./libs/b');

module.exports = 'This is C';
}
},
'./libs/b': {
module.exports = 'This is C';
}),
(_module_['./libs/b'] = {
base: './libs',
dependency: [],
factory: function factory(require, exports, module) {
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.default = void 0;

require('../c');

var _default = 'This is B';
exports.default = _default;
}
},
'./a': {
dependency: []
});
(_module_['./libs/b'].factory = function(require, exports, module) {
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.default = void 0;

require('../c');

var _default = 'This is B';
exports.default = _default;
}),
(_module_['./a'] = {
base: '.',
dependency: [],
factory: function factory(require, exports, module) {
require('./libs/b');

module.exports = 'This is A';
}
},
'./index': {
dependency: []
});
(_module_['./a'].factory = function(require, exports, module) {
require('./libs/b');

module.exports = 'This is A';
}),
(_module_['./index'] = {
base: '.',
dependency: ['./a'],
factory: function factory(A, require, exports, module) {
/* AMD module */
var C = require('./c');

return {
a: A,
c: C,
test: require('test4sample')
};
}
},
test4sample: {
dependency: ['./a']
});
(_module_['./index'].factory = function(A, require, exports, module) {
/* AMD module */
var C = require('./c');

return {
a: A,
c: C,
test: require('test4sample')
};
}),
(_module_['test4sample'] = {
exports: test4sample
}
};
});

return _include_('./index');
});
6 changes: 6 additions & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--require @babel/register
--require @babel/polyfill
--require should
--timeout 3000
--colors
--inline-diffs
2 changes: 1 addition & 1 deletion test/utility.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('Utility', () => {
it(
'Get entry file path from "package.json" of a module',
() => getNPMPackage('koapache').should.be.equal(
'node_modules/koapache/dist/koapache.js'
'node_modules/koapache/dist/WebServer.js'
)
);
});

0 comments on commit 01d8318

Please sign in to comment.