Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add options.defineReplacement #1363

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/finalisers/amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export default function amd ( bundle, magicString, { exportMode, indentString, i
( deps.length ? `[${deps.join( ', ' )}], ` : `` );

const useStrict = options.useStrict !== false ? ` 'use strict';` : ``;
const wrapperStart = `define(${params}function (${args.join( ', ' )}) {${useStrict}\n\n`;
const define = options.defineReplacement || 'define';
const wrapperStart = `${define}(${params}function (${args.join( ', ' )}) {${useStrict}\n\n`;

// var foo__default = 'default' in foo ? foo['default'] : foo;
const interopBlock = getInteropBlock( bundle, options );
Expand Down
1 change: 1 addition & 0 deletions src/rollup.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const ALLOWED_KEYS = [
'banner',
'cache',
'context',
'defineReplacement',
'dest',
'entry',
'exports',
Expand Down
9 changes: 9 additions & 0 deletions test/form/define-replacement/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var path = require('path');

module.exports = {
solo: true,
description: 'defineReplacement',
options: {
defineReplacement: 'enifed'
}
};
10 changes: 10 additions & 0 deletions test/form/define-replacement/_expected/amd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
enifed(function () { 'use strict';

var a = () => {
console.log('props');
};

a();
a();

});
8 changes: 8 additions & 0 deletions test/form/define-replacement/_expected/cjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

var a = () => {
console.log('props');
};

a();
a();
6 changes: 6 additions & 0 deletions test/form/define-replacement/_expected/es.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var a = () => {
console.log('props');
};

a();
a();
11 changes: 11 additions & 0 deletions test/form/define-replacement/_expected/iife.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(function () {
'use strict';

var a = () => {
console.log('props');
};

a();
a();

}());
14 changes: 14 additions & 0 deletions test/form/define-replacement/_expected/umd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
(factory());
}(this, (function () { 'use strict';

var a = () => {
console.log('props');
};

a();
a();

})));
3 changes: 3 additions & 0 deletions test/form/define-replacement/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export var a = () => {
console.log('props');
};
4 changes: 4 additions & 0 deletions test/form/define-replacement/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { a } from "./a.js";
import { a as b } from "./a.js";
a();
b();