How to execute webpack module from <script>?

I wrote an ES6 module that looks something like this:

export default function({makeCurrentVerUrl, verUrl, fileServer, downloadTokenType, appId}) {
    ...
}

When compiling with webpack, it looks something like this:

webpackJsonp([5,7],[
/* 0 */
/***/ function(module, exports) {

    'use strict';

    Object.defineProperty(exports, "__esModule", {
        value: true
    });

    exports.default = function (_ref) {
        var makeCurrentVerUrl = _ref.makeCurrentVerUrl;
        var verUrl = _ref.verUrl;
        var fileServer = _ref.fileServer;
        var downloadTokenType = _ref.downloadTokenType;
        var appId = _ref.appId;

        ...
    };

/***/ }
]);

This is great, but I'm not sure how to run this file and call the default function.

I can turn it on

<script src="/path/to/script.js"></script>

Most likely, I started it automatically, but how can I name the functions that I defined in it from the browser? requirenot defined in my browser.

+4
source share
1 answer

You can install output.libraryin configuration. From docs :

output.library
If installed, export the package as a library. output.libraryname.

, .

output.libraryTarget
:

"var" - , : var Library = xxx ( )

"this" - , : this["Library"] = xxx

"commonjs" - : exports["Library"] = xxx

"commonjs2" - module.exports: module.exports = xxx

"amd" - AMD ( )

"umd" - AMD, CommonJS2

: "var"

myLibrary()
+4

Source: https://habr.com/ru/post/1619400/


All Articles