I am changing the way to build the typescript library with gulp concat + typescript compiler on the Webpack . And I implement es2015 modules .

Now the library can be used with require/import . And also it is necessary to leave the possibility to use the library by classic adding a script to the html header .

Previously, all functions / variables were hidden in the global variable Survey . For this, we used the namespaces typescript namespace Survey {} and all the classes or variables that we wanted to give out had the export keyword.

I deleted the namespaces and transferred everything to the es2015 modules and now, to get the same global variable, I was forced to include imports of all the necessary classes / variables in the input point of the webpack assembly:

https://github.com/dmitrykurmanov/surveyjs/blob/master/webpack/reactStandardIndex.js

Is there any other way to achieve the same, but without creating such a huge and terrible file?

    1 answer 1

    The bottom line is that you really need to collect all the necessary dependencies in one place, in order to later give them a пучком . But you need to give only those dependencies that really will be needed outside.

    And so that the creepy roll becomes less terrible, you can export without importing -

     export { Dependence } from "....."; export Dependence from "....."; export * as Dependence from "....."; // и т.п 
    • Thanks for the answer! This will help to make the file not so terrible, but for some reason, if you use the following syntax: export Default, { Dependence } from "....."; then everything falls with the error Unexpected token . If you do two exports: export Default from "..." and export { Dependence } from "....."; then everything is fine. - duodvk
    • I found out that there is simply no such syntax, which is strange of course. developer.mozilla.org/ru/docs/Web/JavaScript/Reference/… - duodvk
    • Strange, it works for me, but the truth is on a minimal example. Try this: export { default as Default, Dependence } from "..."; . - user220409
    • so it works yes. You can also export * from "..."; if you need to add everything - duodvk