Answer the question
In order to leave comments, you need to log in
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);
/******/ })
/************************************************************************/
/******/ ([ //куча модулей ]);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question