Skip to content

Instantly share code, notes, and snippets.

@anandthakker
Last active September 5, 2020 20:40
Show Gist options
  • Save anandthakker/68b1b63f2c1236e85709aae0f9f80ad9 to your computer and use it in GitHub Desktop.
Save anandthakker/68b1b63f2c1236e85709aae0f9f80ad9 to your computer and use it in GitHub Desktop.
global.fn = d => d + 1;
module.exports = global.fn;
// chunk1.js
define(['exports'], function (exports) { 'use strict';
var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
commonjsGlobal.data = [4, 5, 6];
var shared = commonjsGlobal.data;
exports.* = commonjsGlobal;
exports.default = shared;
});
// thing1.js
define(['./chunk1.js'], function (__chunk1_js) { 'use strict';
__chunk1_js.*.fn = d => d + 1;
var cjs = __chunk1_js.*.fn;
var thing1 = __chunk1_js.default.map(cjs);
return thing1;
});
// thing2.js
define(['./chunk1.js'], function (__chunk1_js) { 'use strict';
var thing2 = __chunk1_js.default.map(d => d + 2);
return thing2;
});
import commonjs from 'rollup-plugin-commonjs';
export default [{
input: ['thing1.js', 'thing2.js'],
output: {
dir: 'out',
format: 'amd'
},
plugins: [
commonjs()
],
experimentalCodeSplitting: true
}]
global.data = [4, 5, 6];
module.exports = global.data;
import e from './shared';
import fn from './cjs';
export default e.map(fn);
import d from './shared';
export default d.map(d => d + 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment