ember.js icon indicating copy to clipboard operation
ember.js copied to clipboard

Ember is minified even in development

Open boris-petrov opened this issue 1 year ago • 12 comments

🐞 Describe the Bug

For a few releases now, running ember serve leads to a minified build even though it's in development. I'm talking about Ember itself.

🔬 Minimal Reproduction

ember new --pnpm ember-development-minified
cd ember-development-minified
pnpm start

Open http://localhost:4200/, open the devtools and check the assets/vendor/ember/ember.js file. It's minified.

😕 Actual Behavior

Minified Ember which is difficult to use and debug.

🤔 Expected Behavior

Not minified Ember.

🌍 Environment

  • Ember: 5.12.0
  • Ember-CLI: 5.12.0
  • Node.js/npm: v23.1.0
  • OS: Linux
  • Browser: N/A

➕ Additional Context

Possibly due to this PR.

boris-petrov avatar Nov 14 '24 11:11 boris-petrov

I checked this with a new app generated with 6.0 and one with 5.12 and assets/vendor/ember/ember.js is not minified but it does have all whitespace removed. Hitting pretty-print in the inspector solves that. Any other clues to reproducing?

kategengler avatar Nov 15 '24 19:11 kategengler

You’re right, yes, it’s not minified but the whitespace removal is very inconvenient. Try debugging in Chrome - one cannot put breakpoints and can’t step-into stuff. Pretty-printing doesn’t help.

boris-petrov avatar Nov 15 '24 20:11 boris-petrov

I had to test to be sure, but I have no problem putting breakpoints nor stepping through even with pretty print.

kategengler avatar Nov 15 '24 20:11 kategengler

@boris-petrov which browser are you using in development? Potentially a difference in handling debugging post pretty-printing?

acorncom avatar Nov 16 '24 08:11 acorncom

I'm not sure how you do it.

chrome-devtools

Here I tried putting a breakpoint on if (obj.isDestroyed) {. Look where it put it. That's in Chrome's devtools. Or is there some other way of pretty-printing which fixes this and the stepping-into experience that I don't know of?

boris-petrov avatar Nov 16 '24 08:11 boris-petrov

I'm not sure -- in my case I can set breakpoints in the - lines and they stay there (on Chrome devtools).

kategengler avatar Nov 19 '24 16:11 kategengler

The culprit seems to be one of these plugins that are added by default. I didn't narrow it down to a specific one.

// plugins added by ember-cli-babel
[
  ['@babel/plugin-transform-class-static-block', { legacy: true }],
  ['@babel/plugin-proposal-decorators', { legacy: true }],
  ['@babel/plugin-proposal-private-property-in-object', { loose: false }],
  ['@babel/plugin-proposal-private-methods', { loose: false }],
  ['@babel/plugin-proposal-class-properties', { loose: false }],
]

The whitespace issue is fixed if I add disableDecoratorTransforms: true to https://github.com/emberjs/ember.js/blob/be20bd3f8ea066050eb91862af5180e10ba37134/lib/index.js#L156-L160

The flag disables all of those babel plugins when building ember.debug.js.

dwickern avatar Feb 26 '25 21:02 dwickern

@NullVoxPopuli any thoughts here?

kategengler avatar Feb 26 '25 21:02 kategengler

is it still an issue in 6.4.0-alpha.3?

NullVoxPopuli avatar Feb 26 '25 22:02 NullVoxPopuli

is it still an issue in 6.4.0-alpha.3?

Yes

dwickern avatar Feb 26 '25 22:02 dwickern

  • classic build: sourcemaps don't appear to work

    • in app code
    • in vendor code
  • with embroider (webpack): (i'm using devtool: 'source-map')

    • source maps are good
    • original ember code is visible
  • with vite

    • sourcemaps are flawless (even better!)
    • without sourcemaps, modules are nearly original

so, I think the path forward here is probably to progress towards vite

NullVoxPopuli avatar Feb 26 '25 23:02 NullVoxPopuli

Ok, so the problem is babel's compact option which, by default, strips whitespace from large files.

It works to set compact: false in ember-cli-babel's source. I've tried a few ways to feed in compact: false from here with no success. Basically it's the same problem as https://github.com/emberjs/ember-cli-babel/issues/302

dwickern avatar Feb 27 '25 18:02 dwickern

is there any downside to setting compact: false in ember-cli-babel?

This is the default we're using in the upcoming new blueprint: https://github.com/ember-cli/ember-app-blueprint/blob/main/files/_js_babel.config.cjs#L40

I threw up: https://github.com/emberjs/ember-cli-babel/pull/521 but haven't tested it locally

NullVoxPopuli avatar Jul 13 '25 20:07 NullVoxPopuli