OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Rollup modules but keep all variables global

  • Thread starter Thread starter Dmitry K.
  • Start date Start date
D

Dmitry K.

Guest
I will simplify code for my problem. So let's assume I have in module1.js

Code:
export class MyClass { };

and in index.js

Code:
import { MyClass } from './module1.js'

var X = MyClass();

Next i want to bundle index.js with rollup in such way that the result file contents should look like this

Code:
class MyClass { };
var X = MyClass();

My goal is to put the result file into script tag and to be able to access all declared variables in global space e.g window.MyClass and window.X from other scripts.

Is there any rollup options or plugins for this purpose?

<p>I will simplify code for my problem. So let's assume I have in <code>module1.js</code></p>
<pre class="lang-js prettyprint-override"><code>export class MyClass { };
</code></pre>
<p>and in <code>index.js</code></p>
<pre class="lang-js prettyprint-override"><code>import { MyClass } from './module1.js'

var X = MyClass();
</code></pre>
<p>Next i want to bundle <code>index.js</code> with <em>rollup</em> in such way that the result file contents should look like this</p>
<pre class="lang-js prettyprint-override"><code>
class MyClass { };
var X = MyClass();
</code></pre>
<p>My goal is to put the result file into <code>script</code> tag and to be able to access all declared variables in global space e.g <code>window.MyClass</code> and <code>window.X</code> from other scripts.</p>
<p>Is there any rollup options or plugins for this purpose?</p>
 

Latest posts

B
Replies
0
Views
1
Blundering Ecologist
B
Top