Correctly babel drag and drop file in ember-cli-build with additional tree

I have some files in my project that I would like to move from a regular application tree and load only in certain situations. Currently, I used broccoli-stewto move the file and broccoli-babel-transpilerto transfer the destination file. However, when I do this, I get an additional object defaultfor the imported files.

this code is added to the top

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var _Ember = _interopRequireDefault(_ember);

and this makes me write the source file with links to ember like Ember["default"].Objectetc. I would not want to have any odd links in the source files, which complicates the understanding of other developers.

This is my current ember-cli-build.jsfile.

/* global require, module */
var stew = require('broccoli-stew');
var esTranspiler = require('broccoli-babel-transpiler');
var EmberApp = require('ember-cli/lib/broccoli/ember-app');

module.exports = function(defaults) {
  var app = new EmberApp(defaults, {
    storeConfigInMeta: false
  });

  var additionalTrees = [];
  var appTree = app.appAndDependencies();

  if (EmberApp.env() !== "production") {
    var jQuery = stew.find(appTree, "bower_components/jquery/dist/jquery.min.js");
    jQuery = stew.mv(jQuery, "bower_components/jquery/dist/jquery.min.js", "assets/jquery.js");

    additionalTrees.push(jQuery);
  }

  function extractRouter(fileName) {
    var router = stew.find(appTree, 'mobile-web/'+ fileName + '.js');
    router = esTranspiler(router, {
      modules: "amd",
      moduleIds: true,
      moduleId: "mobile-web/router"
    });
    router = stew.mv(router, 'mobile-web/'+ fileName + '.js', 'assets/'+ fileName + '.js');
    additionalTrees.push(router);
  }

  extractRouter('router');
  extractRouter('secure-router');

  return app.toTree(additionalTrees);
};
+4
1

esTranspiler modules: "amdStrict":

router = esTranspiler(router, {
  modules: "amdStrict",// here
  moduleIds: true,
  moduleId: "mobile-web/router"
});

"commonStrict", docs. amdScrict .

commonStrict

+3

Source: https://habr.com/ru/post/1612480/


All Articles