How to include comments in a production build


#1

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?


#2

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 http://babeljs.io/docs/usage/api/


#3

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!


#4

I just found some code


#5

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


#6

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


#7

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


#8

Did you use babel or ember-cli-babel ?


#9
  babel: {
    comments: true,
    compact: false,
    auxiliaryCommentBefore: "something"
  }

#10

Super you got this working.


#11

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.