dfreeman / ember-cli-node-assets

Include stylesheets, images and other assets in your Ember app from node modules
MIT License
62 stars 6 forks source link

Question: How do I use this add-on to import a node package for use in a test? #26

Open BitBrit opened 6 years ago

BitBrit commented 6 years ago

There is a 3rd party node package which I would like to use in a component test. I created my import description in ember-cli-build.js:

    nodeAssets: {
      events: {
        srcDir: 'events',
        vendor: {
          include: ['events.js']
        }
      }
    }

I then import the file: app.import('vendor/events/events.js');

And run the test: ember test --serve

But when I do I get the error: Could not find moduleember-resolver`

Which obviously means that none of my tests can run. Can you help me by letting my know what I've done wrong?

dfreeman commented 6 years ago

It looks like that module is using CommonJS, which means it won't run in a browser out of the box. You'll probably want to look at using something like broccoli-rollup in the processTree() hook, or just using ember-browserify instead of this addon.

BitBrit commented 6 years ago

Thanks for the prompt response. I tried ember-browserify but it didn't seem to work; after following the steps in their docs, it still wasn't able to find the module.

I am very new at this but trying to learn quickly so I was wondering you had any good links (in addition to the one you provided above) which give a good description of how the whole build process works in Ember, why some packages work and some don't and how I can control/manipulate what is and isn't available in a built app? Also, perhaps when I should/could use a vendor-shim, browserify or your add-on?

There doesn't seem to be a whole lot of information immediately available (as mentioned at the top of your add-on's readme :-) )so any help or direction you can give would be greatly appreciated.

digiwand commented 6 years ago

just in case anyone runs into this, note that ember-browserify also doesn't support being included in tests. The workaround for them that was discussed is to export the imported node module in a helper and then ignoring that helper in the non-test environment through ember-cli-build https://github.com/ef4/ember-browserify/issues/14

broccoli-rollup was mentioned, but consider using ember-rollup