1

I'm trying to bundle everything into one single file with rollupjs.

main.js file:

import * as ex from 'example-export';

ex.alertMe();

example-export.js file:

export function alertMe() {
    alert('alert!');
};

The command below and it's response:

karl@karl-ux303ln:~/dev/sketch/experiment/socketio$ rollup ./public/js/main.js --output ./public/js/bundle.js --format iife --sourcemap inline
Treating 'example-export' as external dependency
No name was provided for external module 'example-export' in options.globals – guessing 'ex'

The bundle.js file produced:

(function (ex) {
'use strict';

ex.alertMe();

}(ex));
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnVuZGxlLmpzIiwic291cmNlcyI6WyJtYWluLmpzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCAqIGFzIGV4IGZyb20gJ2V4YW1wbGUtZXhwb3J0JztcblxuZXguYWxlcnRNZSgpOyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFFQSxFQUFFLENBQUMsT0FBTyxFQUFFLDs7In0=

I was expecting the example-export module to be included in the bundle.js file. Since this is really new stuff the internet lacks proper examples of this.

I expect the issue has something to do with the --name argument https://github.com/rollup/rollup/wiki/Command-Line-Interface#usage. I cannot however figure out how it's supposed to be used. And let's say if I have multiple exports and imports, how will that look?

2 Answers 2

4

Relative path

If the file is in the same directory:

import * as ex from './example-export';

Via NODE_PATH

If the NODE_PATH env variable is set, then you may add a path from that.

  • If the NODE_PATH is equal to /home/karl/myprojects/mynodeproject/
  • The library your trying to access is located at /home/karl/myprojects/mynodeproject/src/lib/my_library.js
  • And the file you are writing which is currently trying to import my_library is at /home/karl/myprojects/mynodeproject/src/index.js

Then you can use the following in index.js:

import * as ex from 'src/lib/example-export';
Sign up to request clarification or add additional context in comments.

Comments

2

I have tried the example through the Rollup playground page, only thing I needed to change to get it working was change the

import * as ex from 'example-export';

to

import * as ex from './example-export';

Take a look here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.