Is it possible to override the `build` script for asset canister like it is possible for custom canister

for custom canister we can provide a build parameter in dfx.json:

{
  "canisters": {
    "my_canister": {
      "type": "custom",
      "candid": "my_canister.did",
      "wasm": "build/my_canister.wasm",
      "build": "./scripts/build_my_canister.sh"
    }
}

Doing the same on an assets canister seems to have no effect :slightly_frowning_face:

{
  "canisters": {
    "my_assets_canister": {
      "type": "assets",
      "frontend": {
        "entrypoint": "dist/apps/my_asset_canister/index.html"
      },
      "source": ["dist/apps/my_asset_canister/"],
      "build": "./scripts/build_my_asset_canister.sh"
    }
}

Am I missing something :thinking: ?

assets canister is a pre-compiled canister bundled with dfx. You can find it in sdk repo. It’s source code is here.

So no need to “build” an assets canister.

The asset canister will attempt to run npm run build when it is deploying - you can drop your script in a package.json file’s build script

@kpeacock thanks for the response. The problem is that I have a mono repo with multiple frontends relying on different build scripts. So I would like to be able to change the fact that dfx deploy executes npm run build and instead calls whatever script is defined in the build property of the canister definition in dfx.json. I’m currently solving this by building the frontends before calling dfx deploy and adding "build": "echo 'do nothing'" to the package.json to not clobber with my already build assets.

I agree it’s not the most elegant, and we do have a backlog item on allowing people to disable the npm run build invocation. I think your recommendation is a good way to accomplish that.

If you’re using npm workspaces, the differentiation between a "build": "" in the root package and proper build scripts in the workspaces should work out with

npm run build -> nothing
npm run build --workspaces --if-present -> all build jobs run

1 Like