Export to AMD Normalize Issue

I’m trying to figure out how to export a set of canjs components to amd format using a build file like this one: https://gist.github.com/roemhildtg/2a5242c196caadbc4db9#file-build-js

What ends up happening is the template stache file is getting placed in the amd output folder, while the component.js file is getting placed in its relative directory under amd. Like this:

When I require the component.js file using amd, it tries to find the template.stache.js and fails.

1 Like

We are facing the same problem. The stache files are not exported correctly. (?)

This is how our directory structure looks like:

/my-comp
    /dist
        /amd
            /src
                my-comp.js
            /views
                my-comp.stache.js
    /src
        my-comp.js
        /views
            my-comp.stache

We import the component with RequireJS like this
```define([‘components/my-comp/dist/amd/src/my-comp’])````

But the grunt fails because it cannot find ./views/my-comp.stache

Also the generated views/my-comp.stache.js file has an incorrect reference to can/view/stache/mustache_core.
It should be can/view/mustache_core.

define([
    'module',
    'can/view/stache',
    'can/view/stache/mustache_core'
], function (module, stache, mustacheCore) {

I had that same issue with mustache_core. That one has a pretty easy workaround, in your requirejs config or dojoConfig you can do:

      map: {
        '*': {
          'can/util/library': 'can/util/dojo',
          'can/view/stache/mustache_core': 'can/view/mustache_core'
        }
      },

As for the first issue, I hadn’t found a good fix for that either, but I guess in the meantime I just dragged the folders with the stache templates into their relative directory and merge the folders to get it working.

Hey! Sorry to hear this, would love to help. One question

Do you mean steal-tool export is failing (using a grunt task)?

@matthewp No, the grunt build where we use the exported component fails.
Because the views directory is exported outside the src directory, it cannot find my-comp.stache.js file.

I now mannually :sweat: moved the /dist/amd/views directory inside the /dist/amd/src directory and now it builds correctly.
(After I changed can/view/stache/mustache_core to can/view/mustache_core)

@matthewp I’m encountering another related issue. I have several folders each with their own template.stache steal-tools is placing all of the stache templates in the root directory and some of them are getting overwritten on output.

Is there a solution to this problem, or should I just rename the templates to component_name.stache?