Skip to content

Commit

Permalink
fix(bundler): improve compatibility with nodejs global var "global"
Browse files Browse the repository at this point in the history
A simple global var "global" is created before load all AMD modules. This is a practical way to support nodejs global var "global". In future we will build on top of dumberjs to properly support nodejs global vars "global", "process", and "Buffer" (the last two are still not supported transparently in aurelia-cli bundler). With this fix, @babel/polyfill now works as an AMD module.
  • Loading branch information
3cp committed Feb 10, 2019
1 parent 0826e29 commit 02d1cd0
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/build/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ exports.Bundle = class {

if (loaderOptions.configTarget === this.config.name) {
work = work.then(() => {
files.push({ contents: '_aureliaConfigureModuleLoader();'});
// create global var "global" for compatibility with nodejs
files.push({ contents: 'var global = this; _aureliaConfigureModuleLoader();'});
});
}

Expand Down
3 changes: 1 addition & 2 deletions lib/commands/new/buildsystems/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ module.exports = function(project, options) {
{
'path': 'node_modules/aurelia-cli/lib/resources/scripts/configure-bluebird.js',
'env': 'dev'
},
'node_modules/@babel/polyfill/browser.js'
}
],
dependencies: [
// only needs packages not explicitly depend
Expand Down
1 change: 1 addition & 0 deletions lib/resources/src/main-cli.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '@babel/polyfill';
import environment from './environment';

export function configure(aurelia) {
Expand Down
1 change: 1 addition & 0 deletions lib/resources/src/main-cli.template.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '@babel/polyfill';
import environment from './environment';
// @if features.bootstrap='bootstrap'
import 'bootstrap';
Expand Down

0 comments on commit 02d1cd0

Please sign in to comment.