Git Product home page Git Product logo

Comments (11)

ivanbacher avatar ivanbacher commented on May 30, 2024 1

Super. Thank you @Sayan751 and @3cp for the info and fix.

from aurelia.

ivanbacher avatar ivanbacher commented on May 30, 2024

Maybe it has something to do with the @babel/plugin-proposal-decorators plugin in the babel.config.json file

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "loose": true,
        "modules": false,
        "exclude": [
          "@babel/plugin-proposal-dynamic-import"
        ]
      }
    ]
  ],
  "plugins": [
    [
      "@babel/plugin-proposal-decorators",
      {
        "version": "2023-11"
      }
    ],
    "@babel/plugin-syntax-dynamic-import"
  ]
}

from aurelia.

ivanbacher avatar ivanbacher commented on May 30, 2024

I have added a simplified example on the same repo on the test-2 branch

import { inject, IEventAggregator } from 'aurelia';
import { testVarTwo, testObj } from './data.js';

@inject(IEventAggregator)

export class MyElement {
  constructor(ea) {
    this.ea = ea;
  }

  attached() {
    console.log(testVarTwo)
    const a = testObj
  }
}

data.js

const testVarOne = `
Hello this is test var one
`

const testVarTwo = `
${testVarOne}

Hello this is test var two
`

const testObj = {
  one: `${testVarOne}`,
  two: `${testVarOne}`,
}

export {
  testVarTwo,
  testObj
}

When building this for production testVarOne is removed from the bundle.

if I remove @inject(IEventAggregator) from MyElement then everything works as expected.

Screenshot 2024-04-24 at 16 58 03

from aurelia.

ivanbacher avatar ivanbacher commented on May 30, 2024

I have been investigating this a bit.

Using the @containerless decorator causes the same issue. However using the @customElement('my-element') decorator does not.

I have also tried to reproduce this issue using only webpack without aurelia, but have not been able to replicate it.

If I had to take a guess I think it might have something to do with the aurelia-loader plugin?

from aurelia.

Sayan751 avatar Sayan751 commented on May 30, 2024

Hi @ivanbacher! I have looked into this issue briefly. It seems to me that the code are somehow being tree-shaked and not included in the bundle. You can verify this, you make the following change in the webpack configuration.

- devtool: production ? undefined : 'eval-cheap-source-map',
+ devtool: 'eval-cheap-source-map', 

However, I think that it has something to do with how babel is transpiling the new decorators.

I have used ts-loader with your .js files combined with a tsconfig that allows js files, and it worked fine.

//tsconfig.json
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "ESNext",
    "allowJs": true,
  }
}
image

from aurelia.

Sayan751 avatar Sayan751 commented on May 30, 2024

@ivanbacher I have looked further into this. Seems like a babel issue TBH. Opened up babel/babel#16453 with a reproduction https://github.com/Sayan751/babel-webpack-demo.

If you take a look there, you can see that the issue can be reproduced even without the aurelia dependencies.

Closing this issue as it seems that it is not an Aurelia issue after all. Feel free to reopen if you see otherwise.

cc: @bigopon @3cp

from aurelia.

3cp avatar 3cp commented on May 30, 2024

With my limited understanding, I think babel has nothing to do with tree shaking, it's webpack.

from aurelia.

Sayan751 avatar Sayan751 commented on May 30, 2024

You are right. I only suspect that it is an artifact of how Babel is transpiling the code. Because it is working with ts-loader.

from aurelia.

3cp avatar 3cp commented on May 30, 2024

Babel guy pointed out that's terser bug. We may need to adjust webpack config for compression.

from aurelia.

Sayan751 avatar Sayan751 commented on May 30, 2024

Thank you @3cp for taking care of that!

from aurelia.

Sayan751 avatar Sayan751 commented on May 30, 2024

FYI terser/terser#1526

from aurelia.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.