S
S
sanex33392016-04-01 20:43:50
JavaScript
sanex3339, 2016-04-01 20:43:50

How to integrate Webpack and regular JS code?

Let's say there is 1 TypeScript project with commonJS modules, which is built by Webpack into 1 file.
In this project, in the root file, the variable `MyAmazingPieceOfCode` is assigned a class object, inside which everything else is already done (25 classes, for each file).
When all this has gone astray into 1 file, I include it on the page. And this is where I want to use the `MyAmazingPieceOfCode` variable to get the complex analytical data that this project gives. How to do it?
It only comes to mind to shove into window['myAmazingPieceOfCode'].
The thing is that Webpack wraps all the code in

(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);
/******/ })
/************************************************************************/
/******/ ([ //куча модулей ]);

Well, for example, one of the methods of the `MyAmazingPieceOfCode` object will be a method with an argument - a callback that will be executed based on the data.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sanex3339, 2016-04-01
@sanex3339

Asked it myself - answered it myself:
webpack.github.io/docs/library-and-externals.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question