Giter Club home page Giter Club logo

Comments (7)

shabalin avatar shabalin commented on June 10, 2024 22

Finally we figured a root cause - webpack in production mode does Module Concatenation (ModuleConcatenationPlugin enabled in production mode by default) which makes view model inlined into the class that uses it (If you refer to the same VM in multiple places it wouldn't happen).
So one line in webpack config fixes the problem:

  optimization: {
    concatenateModules: false,
  },

Aurelia Webpack Plugin, we suppose, should somehow prevent inlining, like what it does when it processes Platform.moduleName'd module ref.

from dialog.

StrahilKazlachev avatar StrahilKazlachev commented on June 10, 2024

For this to work you will either need to pass the .view(moduleId or ViewStrategy) or use @view()/static $view on the view model class.

from dialog.

shabalin avatar shabalin commented on June 10, 2024

@useview('dialog/dialog.html') on dialog ViewModel fixes the problem, I it would be great to understand how production mode affects the runtime.

from dialog.

StrahilKazlachev avatar StrahilKazlachev commented on June 10, 2024
  1. production mode is quite broad - it varies between webpack, jspm, aurelia-cli and all their configuration options.
  2. Just to be clear, I suggested using @view(), not @useView(). With @useView() you are basically specifying the moduleId of the view to use. So if you are trying to move away from the use of moduleId this will not help.

from dialog.

shabalin avatar shabalin commented on June 10, 2024
  1. sorry for not making this clear, I referred to https://webpack.js.org/concepts/mode/#mode-production
  2. Unfortunately I wasn't able to find any documentation about @view, it's not the same as @inlineView? Could you provide me a link, please?
    I think we just try to make Aurelia conventions work for the production webpack build.

from dialog.

ggayowsky avatar ggayowsky commented on June 10, 2024

I just stumbled across this issue a few moment ago.

The application I am working on is a mixed JS and TS. I have only noticed this problem occurring on view models which are typescript files. JS file seem to work just fine.

Hopefully, that sheds some light on this issue

from dialog.

bigopon avatar bigopon commented on June 10, 2024

@ggayowsky can you give this comment (a the comments after it as well, there's extra example) a look https://discourse.aurelia.io/t/production-build-issue/3774/3 and see if it's somewhat matches your scenario.

An explanation in our Discord chat at https://discord.com/channels/448698263508615178/448699089513611266/755368450058092555

PLATFORM.moduleName when used with webpack will tell Webpack to remove some optimization related to the module being referenced, which will ensures the export names are not mangled to a single letter, or removed entirely when modules are concatenated. If there's no module, Aurelia cannot figure out a view module from the view model, and will result in runtime error. What you can do, if you'd like to use import is use @inlineView, or @useview, or static view via static $view = '' The reason it works now for you, I'm guessing, is that you are in development build, which means webpack optimization not yet kicked in

from dialog.

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.