admin管理员组文章数量:1221299
I am trying to package a bundle.js generated from my react app inside grails war. When I run it in the Intellij IDEA everything works fine. What I have is a npm-app which is a reactjs app which generates a bundle.js using webpack. When I include this bundle like below in my gsp pages it works fine when I run it in Intellij. But, when I package it using grails war, the war file generated does not show the app. The contents of the bundle.js were not included in the packaged War.
<div id="react-root"></div>
<asset:javascript src="bundle.js"/>
</div>
Grails version: 3.3.8 Jdk: 1.8.0_432
This is my gradle.properties
grailsVersion=3.3.8
gormVersion=6.1.10.RELEASE
gradleWrapperVersion=3.5
I've tried to apply the options and asset plugins mentioned in this thread: Grails assets not work in deployed .WAR
Here's how my build.gradle looks like:
buildscript {
repositories {
mavenLocal()
maven { url "; }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "org.grails.plugins:hibernate5:${gormVersion-".RELEASE"}"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.14.8"
}
}
version "0.1"
group "myapp"
apply plugin:"eclipse"
apply plugin:"idea"
apply plugin:"war"
apply plugin:"org.grails.grails-web"
apply plugin:"asset-pipeline"
apply plugin:"org.grails.grails-gsp"
apply plugin:"java"
apply plugin:"io.spring.dependency-management"
war.archiveName='myapp.war'
repositories {
mavenLocal()
maven { url "; }
}
dependencies {
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.grails:grails-core"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
...
}
bootRun {
jvmArgs('-Dspring.output.ansi.enabled=always')
addResources = true
String springProfilesActive = 'spring.profiles.active'
systemProperty springProfilesActive, System.getProperty(springProfilesActive)
}
assets {
minifyJs = true
minifyCss = true
}
jar {
manifest {
attributes 'Main-Class': 'myapp.Application'
}
}
war {
manifest {
attributes 'Main-Class': 'myapp.Application'
}
}
Moreover, for the last section in the above build.gradle, when I was packaging it using Intellij the war was giving "no main manifest attribute" so I've already added the Main-class Attribute.
Can't execute jar- file: "no main manifest attribute"
Please advise how I can make it work he same way it is working inside Intellij. The reactjs app works fine if I run it independently as well so just to confirm that there is no issues with the reactjs app.
Update 2:
I tried to find out if this is because of reactjs minification and I tried excluding the minified files in Application.groovy, Application.yml. This didn't work:
grails.assets = [
minifyJs: false,
minifyCss: true,
minifyOptions: [
excludes: [
'**/jquery-2.2.0.min.js', // Ensure correct path and extension
'**/bundle.js'
]
]
]
application.yml
grails:
assets:
minifyJs: true
minifyCss: true
minifyOptions:
excludes:
- '**/jquery-2.2.0.min.js'
- '**/bundle.js'
I also tried adding this to application.js it still didn't work:
//= bundle.js
I am trying to package a bundle.js generated from my react app inside grails war. When I run it in the Intellij IDEA everything works fine. What I have is a npm-app which is a reactjs app which generates a bundle.js using webpack. When I include this bundle like below in my gsp pages it works fine when I run it in Intellij. But, when I package it using grails war, the war file generated does not show the app. The contents of the bundle.js were not included in the packaged War.
<div id="react-root"></div>
<asset:javascript src="bundle.js"/>
</div>
Grails version: 3.3.8 Jdk: 1.8.0_432
This is my gradle.properties
grailsVersion=3.3.8
gormVersion=6.1.10.RELEASE
gradleWrapperVersion=3.5
I've tried to apply the options and asset plugins mentioned in this thread: Grails assets not work in deployed .WAR
Here's how my build.gradle looks like:
buildscript {
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "org.grails.plugins:hibernate5:${gormVersion-".RELEASE"}"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.14.8"
}
}
version "0.1"
group "myapp"
apply plugin:"eclipse"
apply plugin:"idea"
apply plugin:"war"
apply plugin:"org.grails.grails-web"
apply plugin:"asset-pipeline"
apply plugin:"org.grails.grails-gsp"
apply plugin:"java"
apply plugin:"io.spring.dependency-management"
war.archiveName='myapp.war'
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.grails:grails-core"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
...
}
bootRun {
jvmArgs('-Dspring.output.ansi.enabled=always')
addResources = true
String springProfilesActive = 'spring.profiles.active'
systemProperty springProfilesActive, System.getProperty(springProfilesActive)
}
assets {
minifyJs = true
minifyCss = true
}
jar {
manifest {
attributes 'Main-Class': 'myapp.Application'
}
}
war {
manifest {
attributes 'Main-Class': 'myapp.Application'
}
}
Moreover, for the last section in the above build.gradle, when I was packaging it using Intellij the war was giving "no main manifest attribute" so I've already added the Main-class Attribute.
Can't execute jar- file: "no main manifest attribute"
Please advise how I can make it work he same way it is working inside Intellij. The reactjs app works fine if I run it independently as well so just to confirm that there is no issues with the reactjs app.
Update 2:
I tried to find out if this is because of reactjs minification and I tried excluding the minified files in Application.groovy, Application.yml. This didn't work:
grails.assets = [
minifyJs: false,
minifyCss: true,
minifyOptions: [
excludes: [
'**/jquery-2.2.0.min.js', // Ensure correct path and extension
'**/bundle.js'
]
]
]
application.yml
grails:
assets:
minifyJs: true
minifyCss: true
minifyOptions:
excludes:
- '**/jquery-2.2.0.min.js'
- '**/bundle.js'
I also tried adding this to application.js it still didn't work:
//= bundle.js
Share
Improve this question
edited Feb 7 at 4:07
Amit Thakur
asked Feb 7 at 1:46
Amit ThakurAmit Thakur
214 bronze badges
1 Answer
Reset to default 0I tried a lot of approaches besides the ones mentioned above but nothing seem to work. Also considering I did not want the reactjs components to intrude with the grails javascript I did below workaround - hope this might help someone else stuck with similar situation.
I moved the compiled bundle.js into src/main/resources/ and created this ContentController to serve the file as raw javascript file:
@Controller
class ContentController extends RestfulController{
def bundle(){
def myBundleFileContents = getClass().getResource('/bundle.js').text
response.setHeader("Content-disposition", "filename=bundle.js")
response.contentType = 'text/javascript'
response.outputStream << myBundleFileContents
response.outputStream.flush()
}
//more actions
}
Then I included the bundle file in my gsp page as below:
<script type="text/javascript" src="../content/bundle">
</script>
本文标签: javaGrails 338 javascript bundle assets not being packaged in warStack Overflow
版权声明:本文标题:java - Grails 3.3.8 javascript bundle assets not being packaged in war - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739349921a2159335.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论