mirror of https://github.com/lukechilds/rollup.git
Browse Source
This allows arbitrary `moduleName` (including names with dashes like `ui-router` or scoped npm packages like `@angular/core`) to be added to the global object. Closes #582 Closes #584gh-1132
Chris Thielen
8 years ago
17 changed files with 136 additions and 11 deletions
@ -0,0 +1,17 @@ |
|||
// Generate strings which dereference dotted properties, but use array notation
|
|||
|
|||
const shouldUseDot = /^[a-zA-Z$_][a-zA-Z0-9$_]*$/; |
|||
const dereferenceString = prop => |
|||
prop.match(shouldUseDot) ? `.${prop}` : `['${prop}']`; |
|||
|
|||
/** |
|||
* returns a function which generates property dereference strings for the given name |
|||
* |
|||
* const getGlobalProp = propertyStringFor('global'); |
|||
* getGlobalProp('foo.bar.baz') => `global['foo']['bar']['baz']` |
|||
*/ |
|||
const propertyStringFor = objName => propName => |
|||
objName + propName.split('.').map(dereferenceString).join(''); |
|||
|
|||
|
|||
export default propertyStringFor; |
@ -0,0 +1,6 @@ |
|||
module.exports = { |
|||
description: 'allows module name with dashes to be added to the global object', |
|||
options: { |
|||
moduleName: '@scoped/npm-package' |
|||
} |
|||
}; |
@ -0,0 +1,9 @@ |
|||
define(['exports'], function (exports) { 'use strict'; |
|||
|
|||
let foo = 'foo'; |
|||
|
|||
exports.foo = foo; |
|||
|
|||
Object.defineProperty(exports, '__esModule', { value: true }); |
|||
|
|||
}); |
@ -0,0 +1,7 @@ |
|||
'use strict'; |
|||
|
|||
Object.defineProperty(exports, '__esModule', { value: true }); |
|||
|
|||
let foo = 'foo'; |
|||
|
|||
exports.foo = foo; |
@ -0,0 +1,3 @@ |
|||
let foo = 'foo'; |
|||
|
|||
export { foo }; |
@ -0,0 +1,8 @@ |
|||
(function (exports) { |
|||
'use strict'; |
|||
|
|||
let foo = 'foo'; |
|||
|
|||
exports.foo = foo; |
|||
|
|||
}((this['@scoped/npm-package'] = this['@scoped/npm-package'] || {}))); |
@ -0,0 +1,13 @@ |
|||
(function (global, factory) { |
|||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : |
|||
typeof define === 'function' && define.amd ? define(['exports'], factory) : |
|||
(factory((global['@scoped/npm-package'] = global['@scoped/npm-package'] || {}))); |
|||
}(this, (function (exports) { 'use strict'; |
|||
|
|||
let foo = 'foo'; |
|||
|
|||
exports.foo = foo; |
|||
|
|||
Object.defineProperty(exports, '__esModule', { value: true }); |
|||
|
|||
}))); |
@ -0,0 +1 @@ |
|||
export let foo = 'foo'; |
@ -0,0 +1,6 @@ |
|||
module.exports = { |
|||
description: 'allows module name with dashes to be added to the global object', |
|||
options: { |
|||
moduleName: 'module-name-with-dashes' |
|||
} |
|||
}; |
@ -0,0 +1,9 @@ |
|||
define(['exports'], function (exports) { 'use strict'; |
|||
|
|||
let foo = 'foo'; |
|||
|
|||
exports.foo = foo; |
|||
|
|||
Object.defineProperty(exports, '__esModule', { value: true }); |
|||
|
|||
}); |
@ -0,0 +1,7 @@ |
|||
'use strict'; |
|||
|
|||
Object.defineProperty(exports, '__esModule', { value: true }); |
|||
|
|||
let foo = 'foo'; |
|||
|
|||
exports.foo = foo; |
@ -0,0 +1,3 @@ |
|||
let foo = 'foo'; |
|||
|
|||
export { foo }; |
@ -0,0 +1,8 @@ |
|||
(function (exports) { |
|||
'use strict'; |
|||
|
|||
let foo = 'foo'; |
|||
|
|||
exports.foo = foo; |
|||
|
|||
}((this['module-name-with-dashes'] = this['module-name-with-dashes'] || {}))); |
@ -0,0 +1,13 @@ |
|||
(function (global, factory) { |
|||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : |
|||
typeof define === 'function' && define.amd ? define(['exports'], factory) : |
|||
(factory((global['module-name-with-dashes'] = global['module-name-with-dashes'] || {}))); |
|||
}(this, (function (exports) { 'use strict'; |
|||
|
|||
let foo = 'foo'; |
|||
|
|||
exports.foo = foo; |
|||
|
|||
Object.defineProperty(exports, '__esModule', { value: true }); |
|||
|
|||
}))); |
@ -0,0 +1 @@ |
|||
export let foo = 'foo'; |
Loading…
Reference in new issue