Use webpack for full build, find something else for type checking
This commit is contained in:
14
config/webpack.js
Normal file
14
config/webpack.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
const webpack = require('webpack');
|
||||||
|
const MinifyPlugin = require('babel-minify-webpack-plugin');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
entry: './src/index.js',
|
||||||
|
output: {
|
||||||
|
filename: 'build/ol.js'
|
||||||
|
},
|
||||||
|
devtool: 'source-map',
|
||||||
|
plugins: [
|
||||||
|
new webpack.optimize.ModuleConcatenationPlugin(),
|
||||||
|
new MinifyPlugin()
|
||||||
|
]
|
||||||
|
};
|
||||||
@@ -11,11 +11,11 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "eslint tasks test src examples transforms",
|
"lint": "eslint tasks test src examples transforms",
|
||||||
"pretest": "npm run lint",
|
"pretest": "npm run lint",
|
||||||
"test": "npm run karma -- --single-run && npm run build-typecheck",
|
"test": "npm run karma -- --single-run",
|
||||||
"karma": "karma start test/karma.config.js",
|
"karma": "karma start test/karma.config.js",
|
||||||
"serve-examples": "mkdir -p build/examples && webpack --config examples/webpack/config.js --watch & serve build/examples",
|
"serve-examples": "mkdir -p build/examples && webpack --config examples/webpack/config.js --watch & serve build/examples",
|
||||||
"build-examples": "webpack --config examples/webpack/config.js --env=prod",
|
"build-examples": "webpack --config examples/webpack/config.js --env=prod",
|
||||||
"build-typecheck": "node tasks/generate-index.js && node tasks/build-typecheck.js"
|
"build": "webpack --config config/webpack.js"
|
||||||
},
|
},
|
||||||
"main": "src/ol/index.js",
|
"main": "src/ol/index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ function addImports(symbols, callback) {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate goog code to export a named symbol.
|
* Generate code to export a named symbol.
|
||||||
* @param {string} name Symbol name.
|
* @param {string} name Symbol name.
|
||||||
* @param {Object.<string, string>} namespaces Already defined namespaces.
|
* @param {Object.<string, string>} namespaces Already defined namespaces.
|
||||||
* @return {string} Export code.
|
* @return {string} Export code.
|
||||||
@@ -61,17 +61,12 @@ function formatSymbolExport(name, namespaces) {
|
|||||||
const isNamed = parts[0].indexOf('.') !== -1;
|
const isNamed = parts[0].indexOf('.') !== -1;
|
||||||
const nsParts = parts[0].replace(/^module\:/, '').split(/[\/\.]/);
|
const nsParts = parts[0].replace(/^module\:/, '').split(/[\/\.]/);
|
||||||
const last = nsParts.length - 1;
|
const last = nsParts.length - 1;
|
||||||
let importName = isNamed ?
|
const importName = isNamed ?
|
||||||
'_' + nsParts.slice(0, last).join('_') + '.' + nsParts[last] :
|
'_' + nsParts.slice(0, last).join('_') + '.' + nsParts[last] :
|
||||||
'$' + nsParts.join('$');
|
'$' + nsParts.join('$');
|
||||||
if (parts.length > 1 && parts[1].indexOf('.') !== -1) {
|
|
||||||
const property = parts[1].split('.').pop();
|
|
||||||
importName += '.' + property;
|
|
||||||
nsParts.push(property);
|
|
||||||
}
|
|
||||||
let line = nsParts[0];
|
let line = nsParts[0];
|
||||||
for (let i = 1, ii = nsParts.length; i < ii; ++i) {
|
for (let i = 1, ii = nsParts.length; i < ii; ++i) {
|
||||||
line += `['${nsParts[i]}']`;
|
line += `.${nsParts[i]}`;
|
||||||
namespaces[line] = (line in namespaces ? namespaces[line] : true) && i < ii - 1;
|
namespaces[line] = (line in namespaces ? namespaces[line] : true) && i < ii - 1;
|
||||||
}
|
}
|
||||||
line += ` = ${importName};`;
|
line += ` = ${importName};`;
|
||||||
@@ -79,19 +74,6 @@ function formatSymbolExport(name, namespaces) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate goog code to export a property.
|
|
||||||
* @param {string} name Property long name (e.g. foo.Bar#baz).
|
|
||||||
* @return {string} Export code.
|
|
||||||
*/
|
|
||||||
function formatPropertyExport(name) {
|
|
||||||
const parts = name.split('#');
|
|
||||||
const prototype = parts[0].split('~')[0].replace(/^module\:/, './').replace(/[.\/]+/g, '$') + '.prototype';
|
|
||||||
const property = parts[1];
|
|
||||||
return `${prototype}['${property}'] = ${prototype}.${property};`;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate export code given a list symbol names.
|
* Generate export code given a list symbol names.
|
||||||
* @param {Array.<Object>} symbols List of symbols.
|
* @param {Array.<Object>} symbols List of symbols.
|
||||||
@@ -103,10 +85,11 @@ function generateExports(symbols, namespaces, imports) {
|
|||||||
let blocks = [];
|
let blocks = [];
|
||||||
symbols.forEach(function(symbol) {
|
symbols.forEach(function(symbol) {
|
||||||
const name = symbol.name;
|
const name = symbol.name;
|
||||||
if (name.indexOf('#') > 0) {
|
if (name.indexOf('#') == -1) {
|
||||||
blocks.push(formatPropertyExport(name));
|
const block = formatSymbolExport(name, namespaces);
|
||||||
} else {
|
if (block !== blocks[blocks.length - 1]) {
|
||||||
blocks.push(formatSymbolExport(name, namespaces));
|
blocks.push(block);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const nsdefs = ['const ol = window[\'ol\'] = {};'];
|
const nsdefs = ['const ol = window[\'ol\'] = {};'];
|
||||||
|
|||||||
Reference in New Issue
Block a user