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
implement amd.autoId
/amd.basePath
options
#3867
Changes from 5 commits
cef70d8
a44bef3
eadea09
462c69c
287769a
65f0921
3a42519
04ec70f
3bcd1cd
02b8f21
2e9d487
cb76695
881b932
e3cf09c
95d605f
96088e2
bde40bc
ad09886
114364f
9434622
8eeece1
1654ded
1d4efc9
84e8099
96ea9c1
c9ec971
48d01b1
e1d9173
e6944ae
9cecce3
6ef8520
bba3d17
cbae7b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import removeJsExtension from './removeJsExtension'; | ||
|
||
// AMD resolution will only respect the AMD baseUrl if the .js extension is omitted. | ||
// The assumption is that this makes sense for all relative ids: | ||
// https://requirejs.org/docs/api.html#jsfiles | ||
export default function removeExtensionFromRelativeAmdId(id: string) { | ||
return id[0] === '.' ? removeJsExtension(id) : id; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function removeJsExtension(name: string) { | ||
return name.endsWith('.js') ? name.slice(0, -3) : name; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module.exports = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your test names are switched: The code-split test is not doing the code splitting while the other one does |
||
solo: true, | ||
description: 'handles amd.id with the [id] pattern', | ||
options: { | ||
input: ['main'], | ||
output: { | ||
name: 'outputName', | ||
amd: { | ||
id: 'something/[id]' | ||
} | ||
} | ||
}, | ||
additionalFormats: ['umd'], | ||
runAmd: exports => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not call the function. The correct syntax is
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You will find that To fix this, we should probably extend the runAmd object so that you can specify also the id of the main entry if it is not |
||
return exports.getA(); | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
define('something/main', ['exports'], function (exports) { 'use strict'; | ||
|
||
const something = 42; | ||
|
||
exports.something = something; | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
const something = 42; | ||
|
||
exports.something = something; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const something = 42; | ||
|
||
export { something }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
System.register('outputName', [], function (exports) { | ||
'use strict'; | ||
return { | ||
execute: function () { | ||
|
||
const something = exports('something', 42); | ||
|
||
} | ||
}; | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define('something/main', ['exports'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.outputName = {})); | ||
}(this, (function (exports) { 'use strict'; | ||
|
||
const something = 42; | ||
|
||
exports.something = something; | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
}))); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
solo: true, | ||
description: 'handles amd.id with the [id] pattern and code splitting', | ||
options: { | ||
input: ['main'], | ||
output: { | ||
amd: { | ||
id: 'something/[id]' | ||
} | ||
} | ||
}, | ||
runAmd: true | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
define('something/generated-a', ['exports'], function (exports) { 'use strict'; | ||
|
||
const something = 42; | ||
|
||
exports.something = something; | ||
|
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
define('something/main', ['require', 'exports'], function (require, exports) { 'use strict'; | ||
|
||
function getA() { | ||
return new Promise(function (resolve, reject) { require(['./generated-a'], resolve, reject) }); | ||
} | ||
|
||
exports.getA = getA; | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
const something = 42; | ||
|
||
exports.something = something; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
function getA() { | ||
return Promise.resolve().then(function () { return require('./generated-a.js'); }); | ||
} | ||
|
||
exports.getA = getA; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const something = 42; | ||
|
||
export { something }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function getA() { | ||
return import('./generated-a.js'); | ||
} | ||
|
||
export { getA }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
System.register([], function (exports) { | ||
'use strict'; | ||
return { | ||
execute: function () { | ||
|
||
const something = exports('something', 42); | ||
|
||
} | ||
}; | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
System.register([], function (exports, module) { | ||
'use strict'; | ||
return { | ||
execute: function () { | ||
|
||
exports('getA', getA); | ||
|
||
function getA() { | ||
return module.import('./generated-a.js'); | ||
} | ||
|
||
} | ||
}; | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const something = 42; |
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you use this to allow
UMD
here but really I do not think it makes a lot of sense considering UMD just does not support code-splitting. Instead, use a regular form test for the non-code-splitting case.