New task for bundling dependencies
This commit is contained in:
17
package.json
17
package.json
@@ -32,7 +32,6 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": "2.4.0",
|
"async": "2.4.0",
|
||||||
"browserify": "14.3.0",
|
|
||||||
"closure-util": "1.19.0",
|
"closure-util": "1.19.0",
|
||||||
"derequire": "2.0.6",
|
"derequire": "2.0.6",
|
||||||
"fs-extra": "3.0.0",
|
"fs-extra": "3.0.0",
|
||||||
@@ -46,6 +45,10 @@
|
|||||||
"pbf": "3.0.5",
|
"pbf": "3.0.5",
|
||||||
"pixelworks": "1.1.0",
|
"pixelworks": "1.1.0",
|
||||||
"rbush": "2.0.1",
|
"rbush": "2.0.1",
|
||||||
|
"rollup": "^0.41.6",
|
||||||
|
"rollup-plugin-cleanup": "^1.0.0",
|
||||||
|
"rollup-plugin-commonjs": "^8.0.2",
|
||||||
|
"rollup-plugin-node-resolve": "^3.0.0",
|
||||||
"temp": "0.8.3",
|
"temp": "0.8.3",
|
||||||
"@mapbox/vector-tile": "1.3.0",
|
"@mapbox/vector-tile": "1.3.0",
|
||||||
"walk": "2.3.9"
|
"walk": "2.3.9"
|
||||||
@@ -102,24 +105,20 @@
|
|||||||
},
|
},
|
||||||
"ext": [
|
"ext": [
|
||||||
{
|
{
|
||||||
"module": "rbush",
|
"module": "rbush"
|
||||||
"browserify": true
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"module": "pbf",
|
"module": "pbf",
|
||||||
"name": "PBF",
|
"name": "PBF"
|
||||||
"browserify": true
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"module": "pixelworks",
|
"module": "pixelworks",
|
||||||
"import": "Processor",
|
"import": "Processor"
|
||||||
"browserify": true
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"module": "@mapbox/vector-tile",
|
"module": "@mapbox/vector-tile",
|
||||||
"name": "vectortile",
|
"name": "vectortile",
|
||||||
"import": "VectorTile",
|
"import": "VectorTile"
|
||||||
"browserify": true
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
6
tasks/.eslintrc
Normal file
6
tasks/.eslintrc
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"env": {
|
||||||
|
"node": true,
|
||||||
|
"es6": true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,129 +1,69 @@
|
|||||||
var fs = require('fs-extra');
|
const cleanup = require('rollup-plugin-cleanup');
|
||||||
var path = require('path');
|
const common = require('rollup-plugin-commonjs');
|
||||||
|
const node = require('rollup-plugin-node-resolve');
|
||||||
var async = require('async');
|
const path = require('path');
|
||||||
var browserify = require('browserify');
|
const pkg = require('../package.json');
|
||||||
var derequire = require('derequire');
|
const rollup = require('rollup').rollup;
|
||||||
|
|
||||||
var pkg = require('../package.json');
|
|
||||||
|
|
||||||
var root = path.join(__dirname, '..');
|
|
||||||
var buildDir = path.join(root, 'build', 'ol.ext');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get external module metadata.
|
* Wrap a bundled dependency for consumption by the Compiler.
|
||||||
* @return {Array.<Object>} Array of objects representing external modules.
|
* @param {Object} ext Details from the `ext` object in package.json.
|
||||||
|
* @return {Object} A rollup plugin.
|
||||||
*/
|
*/
|
||||||
function getExternalModules() {
|
function wrap(ext) {
|
||||||
return pkg.ext.map(function(item) {
|
return {
|
||||||
if (typeof item === 'string') {
|
name: 'googup',
|
||||||
return {
|
transformBundle: function(source) {
|
||||||
name: item,
|
let name = `ol.ext.${ext.name || ext.module}`;
|
||||||
module: item,
|
let postamble = '';
|
||||||
main: require.resolve(item),
|
if (ext.import) {
|
||||||
browserify: false
|
name += '.' + ext.import;
|
||||||
};
|
} else {
|
||||||
} else {
|
postamble = `${name} = ${name}.default;\n`;
|
||||||
return {
|
}
|
||||||
module: item.module,
|
return `
|
||||||
name: item.name !== undefined ? item.name : item.module,
|
/**
|
||||||
main: require.resolve(item.module),
|
* @fileoverview
|
||||||
import: item.import,
|
* @suppress {accessControls, ambiguousFunctionDecl, checkDebuggerStatement, checkRegExp, checkTypes, checkVars, const, constantProperty, deprecated, duplicate, es5Strict, fileoverviewTags, missingProperties, nonStandardJsDocs, strictModuleDepCheck, suspiciousCode, undefinedNames, undefinedVars, unknownDefines, unusedLocalVariables, uselessCode, visibility}
|
||||||
browserify: item.browserify !== undefined ? item.browserify : false
|
*/
|
||||||
};
|
goog.provide('${name}');
|
||||||
|
|
||||||
|
/** @typedef {function(*)} */
|
||||||
|
${name} = function() {};
|
||||||
|
|
||||||
|
(function() {${source}}).call(ol.ext);
|
||||||
|
${postamble}`;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrap a CommonJS module in Closure Library accessible code.
|
|
||||||
* @param {Object} mod Module metadata.
|
|
||||||
* @param {function(Error, string)} callback Called with any error and the
|
|
||||||
* wrapped module.
|
|
||||||
*/
|
|
||||||
function wrapModule(mod, callback) {
|
|
||||||
var name = 'ol.ext.' + mod.name;
|
|
||||||
var member = 'module.exports';
|
|
||||||
if (mod.import) {
|
|
||||||
name += '.' + mod.import;
|
|
||||||
member += '.' + mod.import;
|
|
||||||
}
|
|
||||||
var wrap = function(code) {
|
|
||||||
return 'goog.provide(\'' + name + '\');\n' +
|
|
||||||
'/** @typedef {function(*)} */\n' +
|
|
||||||
name + ';\n' +
|
|
||||||
'(function() {\n' +
|
|
||||||
'var exports = {};\n' +
|
|
||||||
'var module = {exports: exports};\n' +
|
|
||||||
'var define;\n' +
|
|
||||||
'/**\n' +
|
|
||||||
' * @fileoverview\n' +
|
|
||||||
' * @suppress {accessControls, ambiguousFunctionDecl, ' +
|
|
||||||
'checkDebuggerStatement, checkRegExp, checkTypes, checkVars, const, ' +
|
|
||||||
'constantProperty, deprecated, duplicate, es5Strict, ' +
|
|
||||||
'fileoverviewTags, missingProperties, nonStandardJsDocs, ' +
|
|
||||||
'strictModuleDepCheck, suspiciousCode, undefinedNames, ' +
|
|
||||||
'undefinedVars, unknownDefines, unusedLocalVariables, uselessCode, visibility}\n' +
|
|
||||||
' */\n' + code + '\n' +
|
|
||||||
name + ' = ' + member + ';\n' +
|
|
||||||
'})();\n';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (mod.browserify) {
|
|
||||||
browserify(mod.main, {standalone: mod.name}).bundle(function(err, buf) {
|
|
||||||
if (err) {
|
|
||||||
callback(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
callback(null, wrap(derequire(buf.toString())));
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
fs.readFile(mod.main, function(err, data) {
|
|
||||||
if (err) {
|
|
||||||
callback(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
callback(null, wrap(data.toString()));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build external modules.
|
|
||||||
* @param {Array.<Object>} modules External modules.
|
|
||||||
* @param {function(Error)} callback Called with any error.
|
|
||||||
*/
|
|
||||||
function buildModules(modules, callback) {
|
|
||||||
async.each(modules, function(mod, done) {
|
|
||||||
var output = path.join(buildDir, mod.name) + '.js';
|
|
||||||
async.waterfall([
|
|
||||||
wrapModule.bind(null, mod),
|
|
||||||
fs.outputFile.bind(fs, output)
|
|
||||||
], done);
|
|
||||||
}, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build all external modules.
|
* Build all external modules.
|
||||||
* @param {function(Error)} callback Called with any error.
|
* @return {Promise} Resolves on successful completion.
|
||||||
*/
|
*/
|
||||||
function main(callback) {
|
function main() {
|
||||||
var modules = getExternalModules();
|
return Promise.all(pkg.ext.map(ext => {
|
||||||
buildModules(modules, callback);
|
const moduleName = ext.name || ext.module;
|
||||||
|
const options = {
|
||||||
|
entry: require.resolve(ext.module),
|
||||||
|
dest: `${path.join(__dirname, '..', 'build', 'ol.ext', moduleName.toLowerCase())}.js`,
|
||||||
|
format: 'iife',
|
||||||
|
moduleName: moduleName,
|
||||||
|
exports: 'named',
|
||||||
|
plugins: [
|
||||||
|
node(),
|
||||||
|
common(),
|
||||||
|
cleanup(),
|
||||||
|
wrap(ext)
|
||||||
|
]
|
||||||
|
};
|
||||||
|
return rollup(options).then(bundle => bundle.write(options));
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
main(function(err) {
|
main().catch(err => {
|
||||||
if (err) {
|
process.stderr.write(`${err.message}\n`, () => process.exit(1));
|
||||||
process.stderr.write(err.message + '\n');
|
|
||||||
process.exit(1);
|
|
||||||
} else {
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user