enonic / xp

Enonic XP
https://enonic.com
GNU General Public License v3.0
202 stars 34 forks source link

dev mode fails runtime on es2015 controllers #6026

Closed ComLock closed 6 years ago

ComLock commented 6 years ago

When you setup a transpilation with for instance webpack you have es2015 files in src which ends up as commonjs files in build. This works fine when not running in dev mode.

However as soon as you run enonic in dev mode it fails rendering controllers as it does not understand the es2015 syntax.

The way I have solved this before is by renaming the .js files in src to .es6 or just *.es Then Enonic XP will only pickup the finished transpiled files in the build folder.

A lot of people dislike having es6 or es extention and want to continue to use the js extentions.

Would it be possible to tell dev mode which paths to look in? Perhaps its already possible.

ComLock commented 6 years ago

https://discuss.enonic.com/t/development-mode-live-reload-and-libs/778/4

srsNov '16 Yes, it's read from build folder and source folder (by default). The gradle-plugin sets a X-SOURCE-DIRS header that the XP server looks for in dev-mode. You can tweak this one if you want. Just build your project and look at MANIFEST.MF file to see what values are set.

ComLock commented 6 years ago

I wonder if setting that X-SOURCE-DIRS header must be done in xp server startup, or if it can be set per app.

alansemenov commented 6 years ago

@aro Alex, do you have any input on this?

aro commented 6 years ago

The X-Source-Paths header in the manifest is set by the gradle plugin.

We could maybe add a setting in the plugin so that source directory is not included in the X-Source-Paths header.

But then, what is the benefit of using dev mode when you have to recompile to ES5 for every change done anyway?

GlennRicaud commented 6 years ago

As Srs said, you can overwrite this X-SOURCE-DIRS. You do this in the build.gradle file of your project. So you could here tell it to only look at the build folder.

app {
    name = project.appName
    displayName = 'MyApp'
    vendorName = 'Enonic'
    vendorUrl = 'https://enonic.com'
    systemVersion = "${xpVersion}"
    devSourcePaths = java.util.Collections.singletonList( new File( '/path/to/my/app/build/folder' ) )
}

But as Aro said, with the transpilation you loose the purpose of DEV mode which is to not have to rebuild/retranspile all the time.