How to include comments in a production build

Hello there and thanks in advance.

I need to produce a production build without minification and uglification. Actually, I already know how to achieve this, by using options as such, in ember-cli-build.js:

var app = new EmberApp(defaults, {
  'ember-cli-uglify': {
    enabled: false
  },

  minifyJS: {
    options: {
      exclude: ['**/app.js']
    }
  }
});

The problem is that I also need to preserve the original comments of all files, or at least the ones serving as annotations.

How can I do that?

I have never done this but perhaps adding babel settings like this works:

var app = new EmberApp(defaults, {
  'ember-cli-uglify': {
    enabled: false
  },

  minifyJS: {
    options: {
      exclude: ['**/app.js']
    }
  },

  babel: {
    comments: true
  }
});

See also @babel/core · Babel

I tried it. Unfortunately, there is only a small subset of options that are passed to Babel. Or, at least, this option should be nested in another one and I don’t know about it. Thanks!

I just found some code

I tried it again. Still, all the comments were removed.

perhaps it changed from babel to ember-cli-babel see

Well, I finally got it to work, but it only does for comments inside a function. For example:

// This comment is excluded

import Object from "@ember/object"

// This one is also excluded

export default Object.create({
  aMethod() {
    // This comment is preserved
  }
})

I will figure out if this is enough

Did you use babel or ember-cli-babel ?

  babel: {
    comments: true,
    compact: false,
    auxiliaryCommentBefore: "something"
  }
1 Like

Super you got this working.

Not really. I think I will have to wrap everything I have inside a function only for this purpose. It would be better if I could simply insert such annotations for all files in their first line.