// index.js
function logA() {
console.log('function logA called');
}
var index = logA();
export default index;
<script type = "module" >
import index from './index.js'
console.log('logA: ', index); <
</script>
CommonJs
// For the browser
# compile to a < script > containing a self - executing
function('iife')
$ rollup main.js--flie bundle.js--format iife
For Node.js
# compile to a CommonJS module('cjs')
$ rollup main.js--file bundle.js--format cjs
For browsers and Node.js
# UMD format requires a bundle name
$ rollup main.js--file bundle.js--format umd--name "myBundle"
For es module
$ rollup. / src / main.js--file. / dist / bundle.js--format es
// 使用 CommonJS,必须导入整个库
// Import a full utils object using CommonJS
var utils = require('utils');
var query = 'Rollup';
// Use the ajax method of the utils object
utils.ajax('https://api.example.com?search=' + query).then(handleResponse);
// 使用 ES6 module,无须导入整个库
// Import ajax function using the ES6 import statement
import {
ajax
} from 'utils';
var query = 'Rollup';
// Calling ajax function
ajax('https://api.example.com?search=' + query).then(handleResponse);