The hash value of the build result varies depending on the absolute path of the working...

Discussão em 'Angular' iniciado por cotton, Outubro 30, 2024.

  1. cotton

    cotton Guest

    My Angular project has been upgraded from Angular 12 to 18. The build system had been changed from webpack to esbuild.

    When I built an upgraded Angular 18 project, I found that even though I hadn't changed anything in the source code, different hash values were calculated if the path to the absolute path of working directory where the build was run was different.

    This is my test commands.

    # download source code once.
    git clone -b my-branch my-repository repo

    # copy same source codes.
    cp -pr repo dir1
    cp -pr repo dir2

    # fetch modules once.
    pushd dir1
    npm install
    popd

    # copy same node_modules to another directory.
    cp -pr dir1/node_modules dir2/.

    # build
    pushd dir1
    ng build --base-href=my-base-href --configuration=my-config
    popd

    # build same source and node_modules (it produce different hash value of dir1)
    pushd dir2
    ng build --base-href=my-base-href --configuration=my-config
    popd


    After checking this behavior, I don't know why, but if in angular.json I specify optimization and sourceMap is false (my-config-1), this behaviours doesn't happen. If I set optimization to false or sourceMap to false (my-config-2), the hash value will change each build.

    "configurations": {
    "my-config-1": {
    "optimization": {
    "scripts": *snip*,
    "styles": { *snip* },
    "fonts": *snip*
    },
    "sourceMap": false
    },
    "my-config-2": {
    "optimization": false,
    "sourceMap": false
    }
    }


    The parameters of angular.json and the result pattern were:

    # optimization sourceMap result
    1 set false hash is not depended on the absolute path of working directory (okay)
    2 false false hash changes
    3 set true hash changes
    4 false true hash changes

    I want the same source code to get the same hash value no matter where I build it or how many times I build it. I don't understand why this difference in results is caused by the optimization or sourceMap settings on angular.json.

    This question has been reorganized because the history of the questions 79088277 in the following URL has become too long.

    Continue reading...

Compartilhe esta Página