eriwen / gradle-js-plugin

Gradle plugin for working with JS
http://eriwen.github.io/gradle-js-plugin
Apache License 2.0
382 stars 113 forks source link

ES6 problem with export and imports #142

Closed ghost closed 7 years ago

ghost commented 7 years ago

I use the google closure compiler... reading documentation, the error can't be solved with: --js_module_root but i don't know when i can use this flag on gradle.

My closure config:

  closure {
    warningLevel = 'QUIET'
    compilationLevel = 'WHITESPACE_ONLY'
    compilerOptions = [
      languageIn: 'ECMASCRIPT6_STRICT',
      languageOut: 'ECMASCRIPT5',
      //moduleRoots: ['src/main/webapp/client/static/js/']
    ]
  }

Any idea?

florian-besser commented 7 years ago

Try this:

closure { warningLevel = 'QUIET' compilerOptions.languageIn="ECMASCRIPT6" compilerOptions.languageOut="ECMASCRIPT5" compilerOptions.processCommonJSModules = true compilerOptions.moduleRoots = ['src/main/webapp/client/static/js/'] compilationLevel = "ADVANCED_OPTIMIZATIONS" }

I'm using version 2.14.1 and that seems to work. Overwrites the property as defined in: https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/CompilerOptions.java

ghost commented 7 years ago

thanks @florian-besser but i can't resolve the problem...

I'm using the com.eriwen.gradle.js.tasks.MinifyJsTask in this task too.

  source = [
    "src/main/webapp/client/static/js/app/angular/v1.5.5/angular.min.js",
    "src/main/webapp/client/static/js/app/angular/v1.5.5/angular-animate.min.js",
    "src/main/webapp/client/static/js/app/angular/v1.5.5/angular-aria.min.js",
    "src/main/webapp/client/static/js/app/angular/v1.5.5/angular-messages.min.js",
    "src/main/webapp/client/static/js/app/angular/v1.5.5/angular-filter.min.js",
    "src/main/webapp/client/static/js/app/angular-material/v1.1.0/angular-material.min.js",
    "src/main/webapp/client/static/js/app/atsclient/app.client.js"
  ]
  dest = file("src/main/webapp/client/dist/js/angular.min.js")
  closure {
    warningLevel = 'QUIET'
    //compilationLevel = 'WHITESPACE_ONLY'
    compilerOptions.languageIn="ECMASCRIPT6"
    compilerOptions.languageOut="ECMASCRIPT5"
    compilerOptions.angularPass=true
    compilerOptions.processCommonJSModules=true
    compilerOptions.moduleRoots=['src/main/webapp/client/static/js/app/atsclient/']
    compilationLevel = "ADVANCED_OPTIMIZATIONS"
  }
import { configuration } from 'config'

When i try to import file using this example in app.client.js and config.js are in the same directory that app.client.s (moduleRoots), i've this error my/largepath... ERROR - Failed to load module "./config" import { configuration } from './config';

ghost commented 7 years ago

The config file is, i think that i'm exporting the config:

'use strict';

let configuration = { ... }

export configuration;
brookhong commented 5 years ago

@dankkomcg have you succeeded to import a file?

Mike-the-one commented 4 years ago

@dankkomcg I have the same problem. Do you have a solution for it? thanks