const loaderUtils = require('loader-utils');

module.exports = function(source, map) {
  const options = loaderUtils.parseQuery(this.query);
  const moduleId = options.moduleId;
  this.cacheable();

  const newSource = source + `
import {Origin as __au_o__} from 'aurelia-metadata';
for (var exportName in module.exports) {
  __au_o__.set(module.exports[exportName], new __au_o__(${JSON.stringify(moduleId)}, exportName));
}`;

  this.callback(null, newSource, map);

  if (options.debug) {
    console.log('changed source query', options);
  }
}

@@ -235,14 +235,29 @@
 rt %7B
-Origin
+ensureOriginOnExports
  as 
@@ -261,17 +261,22 @@
 as __au_
-o
+ensure
 __%7D from
@@ -289,116 +289,55 @@
 lia-
-metadata';%0Afor (var exportName in module.exports) %7B%0A  __au_o__.set(module.exports%5BexportName%5D, new __au_o__(
+loader-webpack';%0A__au_ensure__(module.exports, 
 $%7BJS
@@ -363,25 +363,10 @@
 Id)%7D
-, exportName));%0A%7D
+);
 %60;%0A%0A

move origin setting out to loader-webpack