Gururaja Hegde
Gururaja Hegde

Reputation: 373

In flutter web is there a equivalent for reactjs package.json "prebuild"

We have a single package which is built for different sites, which needs some prebuild steps to be executed before actual build steps.

In flutter android, these steps are executed in "preBuild.dependsOn" (in android/app/build.gradle)

Edit (additional info):

MyFlutterMob/android/app/build.gradle

Following prebuild steps are run :

  def option = System.getenv('APK_FOR')

  setConfig()
  {
         if(option == "DEMO"){
             copy{
                 from "../../DemoAppAsset/AppLogo.png"
                 into "../../assets/images" 
             }
         }
         else if(option == "PROD"){
             copy{
                 from "../../ProdAppAsset/AppLogo.png"
                 into "../../assets/images" 
             }
         }
  }

  preBuild.dependsOn setConfig

Is same possible in flutter web build (Not able to find gradle script for same )

Upvotes: 4

Views: 812

Answers (2)

Gururaja Hegde
Gururaja Hegde

Reputation: 373

Wrote shall scrip which takes environment name(PROD1/PROD2/UAT/... ) as input and copies the required "images to white label" /"theme colour list files"/"strings list configs" into respective folders before running "flutter build web". Although it restricts all release to happen from linux / maintain equivalent bat file for windows, broadly it works out.

Upvotes: 0

Guilherme Gabanelli
Guilherme Gabanelli

Reputation: 566

If you are using VSCode, I think you can set a prebuild in launch.json, as is explained here

Basically you can setup your .vscode/launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Flutter",
            "request": "launch",
            "type": "dart",
        }
    ]
}

then, you should create a file tasks.json in the same folder, and add a script that will do what you want (for example a npm script)

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "npm",
            "script": "copyClientConfiguration",
            "problemMatcher": []
        }
    ]
}

and lastly you can add this task as preLaunchTask in launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Flutter",
            "request": "launch",
            "type": "dart",
            "preLaunchTask": "npm: copyClientConfiguration"
        }
    ]
}

Upvotes: 1

Related Questions