Build two bundles: full and lean
The lean bundle does not include any of the runtime packages
(currently just hammerjs and d3) and assumes they'll be available
at runtime in the global namespace.
DELETE
external.config.js
-var path = require('path');
-var UglifyJsPlugin = require('uglifyjs-webpack-plugin');
-
-module.exports = {
- /* webpack 4
- mode: 'production',
- */
- performance: {hints: false},
- cache: true,
- context: path.join(__dirname, 'src'),
- entry: {
- 'geo.ext': './vendor.js',
- 'geo.ext.min': './vendor.js'
- },
- output: {
- path: path.join(__dirname, 'dist', 'built'),
- publicPath: 'dist/built',
- filename: '[name].js'
- },
- resolve: {
- alias: {
- d3: 'd3/d3.js',
- hammerjs: 'hammerjs/hammer.js'
- }
- },
- /* webpack 3 */
- plugins: [
- new UglifyJsPlugin({
- include: /\.min\.js$/,
- parallel: true,
- uglifyOptions: {
- compress: true,
- comments: /@(license|copyright)/
- },
- sourceMap: true
- })
- ],
- /* end webpack 3 */
- /* webpack 4
- optimization: {
- minimizer: [
- new UglifyJsPlugin({
- include: /\.min\.js$/,
- parallel: true,
- uglifyOptions: {
- compress: true,
- comments: /@(license|copyright)/
- },
- sourceMap: true
- })
- ]
- },
- */
- module: {
- rules: [{
- test: require.resolve('d3'),
- use: ['expose-loader?d3']
- }, {
- test: require.resolve('hammerjs'),
- use: ['expose-loader?hammerjs']
- }]
- }
-};

MODIFY
package-lock.json
package-lock.json
{
"name": "geojs",
- "version": "0.16.0",
+ "version": "0.17.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
},
"event-stream": {
"version": "0.5.3",
- "resolved": "http://registry.npmjs.org/event-stream/-/event-stream-0.5.3.tgz",
+ "resolved": "https://registry.npmjs.org/event-stream/-/event-stream-0.5.3.tgz",
"integrity": "sha1-t3uTCfcQet3+q2PwwOr9jbC9jBw=",
"dev": true,
"requires": {
},
"onetime": {
"version": "1.1.0",
- "resolved": "http://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz",
+ "resolved": "https://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz",
"integrity": "sha1-ofeDj4MUxRbwXs78vEzP4EtO14k=",
"dev": true
},
}
}
},
+ "webpack-merge": {
+ "version": "4.1.4",
+ "resolved": "https://registry.npmjs.org/webpack-merge/-/webpack-merge-4.1.4.tgz",
+ "integrity": "sha512-TmSe1HZKeOPey3oy1Ov2iS3guIZjWvMT2BBJDzzT5jScHTjVC3mpjJofgueEzaEd6ibhxRDD6MIblDr8tzh8iQ==",
+ "dev": true,
+ "requires": {
+ "lodash": "4.17.10"
+ }
+ },
"webpack-serve": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/webpack-serve/-/webpack-serve-1.0.4.tgz",

MODIFY
package.json
package.json
"url-loader": "^1.0.1",
"webpack": "^3.12.0",
"webpack-cli": "^2.1.3",
+ "webpack-merge": "^4.1.4",
"webpack-serve": "^1.0.2",
"xmlbuilder": "^10.0.0"
},
"scripts": {
- "build": "webpack --config webpack.config.js && webpack --config external.config.js",
+ "build": "webpack --config webpack.config.js && webpack --config webpack-lean.config.js",
"build-examples": "node examples/build.js && webpack --config webpack-examples.config.js",
"build-website-examples": "node examples/build-website.js && webpack --config webpack-website-examples.config.js",
"build-tutorials": "node tutorials/build.js && webpack --config webpack-tutorials.config.js",

ADD
webpack-lean.config.js
+// The lean build does not include any of the third-party runtime dependencies, rather
+// it assume they are in the global namespace at runtime.
+var config = require('./webpack.base.config');
+var merge = require('webpack-merge');
+
+module.exports = merge(config, {
+ entry: {
+ 'geo.lean': './index.js',
+ 'geo.lean.min': './index.js'
+ },
+ externals: {
+ d3: 'd3',
+ hammerjs: {
+ root: 'Hammer',
+ commonjs: 'hammerjs',
+ commonjs2: 'hammerjs',
+ amd: 'hammerjs',
+ // Since GeoJS's libraryTarget is "umd", defining this (undocumented) external library type
+ // will allow Webpack to create a better error message if a "hammerjs" import fails
+ umd: 'hammerjs'
+ }
+ }
+});

ADD
webpack.base.config.js
+var path = require('path');
+var webpack = require('webpack');
+var exec = require('child_process').execSync;
+var UglifyJsPlugin = require('uglifyjs-webpack-plugin');
+var sha = '';
+
+if (!exec) {
+ console.warn('Node 0.12 or greater is required for detecting the git hash.');
+}
+
+try {
+ sha = exec('git rev-parse HEAD', {cwd: __dirname}).toString().trim();
+} catch (e) {
+ console.warn('Could not determine git hash.');
+}
+
+var define_plugin = new webpack.DefinePlugin({
+ GEO_SHA: JSON.stringify(sha),
+ GEO_VERSION: JSON.stringify(require('./package.json').version)
+});
+
+module.exports = {
+ /* webpack 4
+ mode: 'production',
+ */
+ performance: {hints: false},
+ cache: true,
+ devtool: 'source-map',
+ context: path.join(__dirname, 'src'),
+ output: {
+ path: path.join(__dirname, 'dist', 'built'),
+ publicPath: 'dist/built',
+ filename: '[name].js',
+ library: 'geo',
+ libraryTarget: 'umd'
+ },
+ resolve: {
+ alias: {
+ jquery: 'jquery/dist/jquery',
+ proj4: 'proj4/lib',
+ vgl: 'vgl/vgl.js',
+ d3: 'd3/d3.js',
+ hammerjs: 'hammerjs/hammer.js',
+ mousetrap: 'mousetrap/mousetrap.js'
+ }
+ },
+ plugins: [
+ /* webpack 3 */
+ new UglifyJsPlugin({
+ include: /\.min\.js$/,
+ parallel: true,
+ uglifyOptions: {
+ compress: true,
+ comments: /@(license|copyright)/
+ },
+ sourceMap: true
+ }),
+ /* end webpack 3 */
+ define_plugin
+ ],
+ /* webpack 4
+ optimization: {
+ minimizer: [
+ new UglifyJsPlugin({
+ include: /\.min\.js$/,
+ parallel: true,
+ uglifyOptions: {
+ compress: true,
+ comments: /@(license|copyright)/
+ },
+ sourceMap: true
+ })
+ ]
+ },
+ */
+ module: {
+ rules: [{
+ test: /\.styl$/,
+ use: [
+ 'style-loader',
+ 'css-loader',
+ 'stylus-loader'
+ ]
+ }, {
+ test: /\.css$/,
+ use: [
+ 'style-loader',
+ 'css-loader'
+ ]
+ }, {
+ test: /vgl\.js$/,
+ use: [
+ 'expose-loader?vgl',
+ 'imports-loader?mat4=gl-mat4,vec4=gl-vec4,vec3=gl-vec3,$=jquery'
+ ]
+ }]
+ }
+};

MODIFY
webpack.config.js
webpack.config.js
-var path = require('path');
-var webpack = require('webpack');
-var exec = require('child_process').execSync;
-var UglifyJsPlugin = require('uglifyjs-webpack-plugin');
-var sha = '';
+var config = require('./webpack.base.config');
+var merge = require('webpack-merge');
-if (!exec) {
- console.warn('Node 0.12 or greater is required for detecting the git hash.');
-}
-
-try {
- sha = exec('git rev-parse HEAD', {cwd: __dirname}).toString().trim();
-} catch (e) {
- console.warn('Could not determine git hash.');
-}
-
-var define_plugin = new webpack.DefinePlugin({
- GEO_SHA: JSON.stringify(sha),
- GEO_VERSION: JSON.stringify(require('./package.json').version)
-});
-
-module.exports = {
- /* webpack 4
- mode: 'production',
- */
- performance: {hints: false},
- cache: true,
- devtool: 'source-map',
- context: path.join(__dirname, 'src'),
+module.exports = merge(config, {
entry: {
- geo: './index.js',
+ 'geo': './index.js',
'geo.min': './index.js'
- },
- output: {
- path: path.join(__dirname, 'dist', 'built'),
- publicPath: 'dist/built',
- filename: '[name].js',
- library: 'geo',
- libraryTarget: 'umd'
- },
- resolve: {
- alias: {
- jquery: 'jquery/dist/jquery',
- proj4: 'proj4/lib',
- vgl: 'vgl/vgl.js',
- d3: 'd3/d3.js',
- hammerjs: 'hammerjs/hammer.js',
- mousetrap: 'mousetrap/mousetrap.js'
- }
- },
- externals: {
- d3: 'd3',
- hammerjs: {
- root: 'Hammer',
- commonjs: 'hammerjs',
- commonjs2: 'hammerjs',
- amd: 'hammerjs',
- // Since GeoJS's libraryTarget is "umd", defining this (undocumented) external library type
- // will allow Webpack to create a better error message if a "hammerjs" import fails
- umd: 'hammerjs'
}
- },
- plugins: [
- /* webpack 3 */
- new UglifyJsPlugin({
- include: /\.min\.js$/,
- parallel: true,
- uglifyOptions: {
- compress: true,
- comments: /@(license|copyright)/
- },
- sourceMap: true
- }),
- /* end webpack 3 */
- define_plugin
- ],
- /* webpack 4
- optimization: {
- minimizer: [
- new UglifyJsPlugin({
- include: /\.min\.js$/,
- parallel: true,
- uglifyOptions: {
- compress: true,
- comments: /@(license|copyright)/
- },
- sourceMap: true
- })
- ]
- },
- */
- module: {
- rules: [{
- test: /\.styl$/,
- use: [
- 'style-loader',
- 'css-loader',
- 'stylus-loader'
- ]
- }, {
- test: /\.css$/,
- use: [
- 'style-loader',
- 'css-loader'
- ]
- }, {
- test: /vgl\.js$/,
- use: [
- 'expose-loader?vgl',
- 'imports-loader?mat4=gl-mat4,vec4=gl-vec4,vec3=gl-vec3,$=jquery'
- ]
- }]
- }
-};
+});

Build two bundles: full and lean

The lean bundle does not include any of the runtime packages
(currently just hammerjs and d3) and assumes they'll be available
at runtime in the global namespace.