Nx: docs: is there any way how to copy files when building libs/apps via glob

Created on 17 Dec 2019  路  6Comments  路  Source: nrwl/nx

misc question / discussion

All 6 comments

More often than not, building apps would usually have an asset property. For example, building apps would usually have an asset property you can specify in the workspace.json or angular.json.
You can read more here: https://nx.dev/react/api/web/builders/build#assets

With libs, there usually isn't an asset property you can specify when building those.

Yes there is.
It's available via the angular app config.

// the key is within: projects.myapp.architect.options
"assets": [
              "apps/app/src/favicon.ico",
              "apps/app/src/robots.txt",
              "apps/app/src/manifest.webmanifest",
              {
                "glob": "**/*",
                "input": "libs/shared/ui-theme/assets",
                "output": "./assets"
              }
            ],

This will copy all files from the assets folder of ui-theme into assets

so libs/shared/ui-theme/assets/img/logo.png will become the same as apps/app/assets/img/logo.png

@leon
How about Style sheets, can we store style sheet as well in the shared folder then copy it to assets folder at the time of build.

@leon
How about Style sheets, can we store style sheet as well in the shared folder then copy it to assets folder at the time of build.

That can be done in similar way via <target>.options.styles https://nx.dev/react/api/web/builders/build#styles

demo: https://github.com/nrwl/nx-examples/blob/master/angular.json#L38-L41

More often than not, building apps would usually have an asset property. For example, building apps would usually have an asset property you can specify in the workspace.json or angular.json.
You can read more here: https://nx.dev/react/api/web/builders/build#assets

With libs, there usually isn't an asset property you can specify when building those.

this answer is enough, thx @Cammisuli , Closing

@leon , your sample would copy robots.txt to ./dist/assets/robots.txt

But according to https://www.robotstxt.org , this file should be in project root.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jasedwards picture jasedwards  路  3Comments

Koslun picture Koslun  路  3Comments

zachnewburgh picture zachnewburgh  路  3Comments

ZempTime picture ZempTime  路  3Comments

joelmuskwe picture joelmuskwe  路  3Comments