webpack importing exports unnecessarily

By archytect

new to webpack and es6 modules,

I have two simple functions, one for square the other for drag, I’m only trying to export and import square. why does diag get added into the bundle at all? isn’t the point to only load what’s needed?

test.js

function square(x) {
    return x * x;
}
function diag(x, y) {
    return sqrt(square(x) + square(y));
}
export { square }

index.js

import { square } from './test';

webpack

webpack
Hash: 9a7d113bc9fb07b1955e
Version: webpack 1.13.1
Time: 494ms
         Asset     Size  Chunks             Chunk Names
pages/index.js  1.74 kB       0  [emitted]  pages/index
    + 2 hidden modules
cat public/pages/index*
/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId])
/******/ 			return installedModules[moduleId].exports;
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			exports: {},
/******/ 			id: moduleId,
/******/ 			loaded: false
/******/ 		};
/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ 		// Flag the module as loaded
/******/ 		module.loaded = true;
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;
/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;
/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";
/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
	'use strict';
	var _test = __webpack_require__(1);
/***/ },
/* 1 */
/***/ function(module, exports) {
	"use strict";
	Object.defineProperty(exports, "__esModule", {
	    value: true
	});
	function square(x) {
	    return x * x;
	}
	function diag(x, y) {
	    return sqrt(square(x) + square(y));
	}
	exports.square = square;
/***/ }
/******/ ]);

webpack.config.js

cat webpack.config.js
module.exports = {
	entry: {
		'pages/index': './src/pages/index.js'
	},
	output: {
		path: './public',
		filename: '[name].js'
	},
	module: {
		loaders: [
			{
				test: /.js/,
				loader: 'babel',
				query: {
					presets: ['es2015']
				}
			}
		],
	}
};

Source: Stack Overflow

    

Share it with your friends!

    Fatal error: Uncaught Exception: 12: REST API is deprecated for versions v2.1 and higher (12) thrown in /home/content/19/9652219/html/wp-content/plugins/seo-facebook-comments/facebook/base_facebook.php on line 1273