kratiahuja / fastboot-transform

Transforms given broccoli tree that contains browser API to be fastboot complaint
14 stars 7 forks source link

Should this work with amd transform? #5

Open RobbieTheWagner opened 7 years ago

RobbieTheWagner commented 7 years ago

I am doing:

/* eslint-env node */
'use strict';

const fastbootTransform = require('fastboot-transform');

module.exports = {
  name: 'ember-headroom',

  options: {
    nodeAssets: {
      'headroom.js': {
        vendor: {
          include: ['dist/headroom.min.js'],
          processTree(input) {
            return fastbootTransform(input);
          }
        }
      }
    }
  },

  included() {
    this._super.included.apply(this, arguments);

    this.import('vendor/headroom.js/dist/headroom.min.js', {
      using: [{ transformation: 'amd', as: 'headroom' }]
    });
  }
};

And I get:

There was an error running your app in fastboot. More info about the error: 
 Error: Could not find module `headroom` imported from `mentrs-app/components/nav-bar/component`

Does the amd transform stuff mess up the fastboot-transform stuff?

kratiahuja commented 7 years ago

What's the output after both the transformation?

It looks like the AMD transformation is getting wrapped with the fastboot check so your import headroom from 'components/nav-bar/component' is failing I believe. Ideally you shouldn't be wrapping AMD modules with fastboot check. I think you want to have AMD wrap the fastboot check?

I assume you could have both the transforms existing together as long you make sure the import returns something. For the record, I have an RFC in ember-cli : https://github.com/ember-cli/rfcs/pull/108 that will make this super easy to import. However, the caller has to make sure to import it with care.

Duder-onomy commented 6 years ago

Just got here in my journey as well. We have something using the 'amd' transform and I need it to also use the 'fastBoot' transform.

I see that #470 was merged (RAWK!) , but does not help addons...

Is there a workaround for this yet?