node-gradle / gradle-node-plugin

Gradle plugin for integrating NodeJS in your build. :rocket:
Apache License 2.0
602 stars 118 forks source link

Building strapi results in empty output folder #172

Closed polaroidkidd closed 1 year ago

polaroidkidd commented 3 years ago

I'm trying to build strapi using this plugin, but for some reason I always get an empty output folder, even though the logs show that it's being build (and the time spent building is the same it takes to build it using yarn).

You can reproduce it using my project (branch feat/scaffolding, the specific build task is located here and looks like this

val buildTaskUsingYarn =tasks.register<YarnTask>("buildYarn") {
  inputs.dir("config")
  inputs.dir("api")
  inputs.dir("public")
  inputs.dir("extensions")
  outputs.dir(buildDir)
  yarnCommand.set(listOf("run", "cms:build"))
}

I've tried rearranging the inputs.dir and output.dir but it all resulted in the same problem. I'm fairly sure this isn't actually an issue with your plugin but a misconfiguration of the task on my part. Regardless, I'd be grateful for any pointers on how to fix this.

deepy commented 3 years ago

Could you try building it with --scan and link to the build scan here? The link to the repository provided 404s, it might be a private repository

The order of inputs and outputs doesn't matter and will only affect when Gradle re-runs the task (and how it's cached if caching is enabled on the task)

So in short, if you want to change where the output is you need to configure yarn to do that, this plugin runs yarn run cms:build from the project directory (or workingDir) if set. (You do still want inputs and outputs to be correct so that Gradle doesn't re-run the task unless the input or output has changed :-) )

polaroidkidd commented 3 years ago

oh, my bad. I've made it public now. Here are the results of the scan: https://scans.gradle.com/s/3xov5g6jvrmg4

deepy commented 3 years ago

Looking at the buildscan it seems to be running fine, there's the:

$ strapi build
Building your admin UI with development configuration ...
ℹ Compiling Webpack |  
Done in 9.40s.

I can't find any webpack configuration so it might default to creating a main.js which I'd expect to see in the cms directory, or possibly in a dist folder in there

polaroidkidd commented 3 years ago

Running it with the yarn command yarn run cms:build creates a build folder with the build output. I think the webpack configuration comes from on of folders inside node_modules from strapi.

deepy commented 3 years ago

Ah, but the gradle task yarnBuild does not create that build folder?

polaroidkidd commented 3 years ago

it creates the build folder, but after the task is complete, it remains empty.

deepy commented 3 years ago

Having taken another look at this there's 2 things that stand out:

Apart from that, everything looks like expected, it might be that yarn install might need to be run, but as far as I can tell things are setup like expected and the gradle plugin is doing what it should (i.e. starting yarn with the correct parameters)

polaroidkidd commented 3 years ago

Hi

I fixed the broken gradle wrapper and added the yarn install task dependency (http://github.com/polaroidkidd/wichtel/blob/ac5df7e2ceb7f22a7b06599067478af3860293e3/cms/build.gradle.kts#L31-L31).

When I run the ./gradlew buildYarn task I still get an empty build folder, however, I've noticed that the .cache folder contains (what I assume) an uncompiled strapi admin panel version. The generated package.json in the .cache folder appears to match the package.json from their repository: https://github.com/strapi/strapi/blob/master/packages/strapi-admin/package.json

Could it be that strapi is expecting the webpack build files to be somewhere else and errors out of the build silently when it can't find them?